How to convert a string to Date in red - red

If I accept a date from a user using ask and then wish to use it as a Date by using to-date, I get an error.
>> to-date "31-Dec-2019"
*** Script Error: cannot MAKE/TO date! from: "31-Dec-2019"
*** Where: to
*** Stack: to-date
What is the correct way of converting a string to date ?

You have to use load
>> load "31-Dec-2019"
== 31-Dec-2019
a few examples for to-date!
>> to-date 1547196008
== 11-Jan-2019/8:40:08
>> to-date [200 1 1]
== 1-Jan-0200

Related

OSError: This docstring was not generated by Nipype

Hey i am runing the following piece of code:
import nipype.interfaces.spm as spm
realign = spm.Realign()
And getting the following error:
raise IOError("This docstring was not generated by Nipype!\n") from e
OSError: This docstring was not generated by Nipype!
After debugging:
My code:
spm.Realign()
When this runs it uses matlab to run the follwing (base.py lines 217):
mlab.inputs.script = """
if isempty(which('spm')),
throw(MException('SPMCheck:NotFound','SPM not in matlab path'));
end;
spm_path = spm('dir');
[name, version] = spm('ver');
fprintf(1, 'NIPYPE path:%s|name:%s|release:%s', spm_path, name, version);
exit;
"""
try:
out = mlab.run()
I run it in Matlab and got :
>> isempty(which('spm'))
ans =
logical
0
>> [name, version] = spm('ver');
fprintf(1, 'NIPYPE path:%s|name:%s|release:%s', spm_path, name, version);
NIPYPE path:C:\Program Files\MATLAB\R2022b\toolbox\spm12\spm12|name:SPM12|release:7771
so as you can see I have result from this script, but when checking the "out" variable here (line 239):
out = sd._strip_header(out.runtime.stdout)
Stdout is "" empty string
So I think the problem is Somehow related to the answer of the script from Matlab, how to fix it ??
Thanks!

How to use external real-trace mobility model in ONE simulator?

I am trying to run a simulation in ONE simulator using the haggle-one-infocom2006-complete model from CRAWDAD, but I'm getting an error saying:
Can't start: error in configuration file(s)
Invalid offset line '1 CONN 16 12 up'
Here is how I specified it in the settings:
Group.movementModel = ExternalMovement
ExternalMovement.file = haggle-one-infocom2006-complete.txt
The first line of the input file should contain offset information:
minTime maxTime minX maxX minY maxY minZ maxZ
See the ExternalMovementReader class for details.

Jython 2.5 isdigit

I am trying to add an isdigit() to the program so that I can verify what the user enters is valid. This is what I have so far. But when I run it an enter a character, say "f". It crashes and gives me the error which will be posted below the code. Any ideas?
def mirrorHorizontal(source):
userMirrorPoint = requestString("Enter a mirror point from 0 to halfway through the pitcure.") #asks user for an input
while (int(userMirrorPoint) < 0 or int(userMirrorPoint) > (int(getHeight(source) - 1)//2)) or not(userMirrorPoint.isdigit()):
userMirrorPoint = requestString("Enter a mirror point from 0 to halfway through the pitcure.")
height = getHeight(source)
mirrorPoint = int(userMirrorPoint)
for x in range(0, getWidth(source)):
for y in range(0, mirrorPoint):
topPixel = getPixel(source, x, y)
bottomPixel = getPixel(source, x, height-y-1)
color = getColor(topPixel)
setColor(bottomPixel, color)
The error was: f
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
Please check line 182 of /Volumes/FLASHDRIVE2/College/Spring 16'/Programs - CPS 201/PA5Sikorski.py
isdigit() itself behaves itself in the 2.7.0 jython version I have locally
>>> '1'.isdigit()
True
>>> ''.isdigit()
False
>>> 'A'.isdigit()
False
>>> 'A2'.isdigit()
False
>>> '2'.isdigit()
True
>>> '22321'.isdigit()
True
Try breaking your big expression up, as typecasting to integers will throw errors for non-numeric strings. This is true across Python versions.
>>> int('b')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'b'
>>> int('2')
2
You probably want to be careful about the order of the parts of that long expression (this or that or ...). Breaking it up would also make it more readable.

Error reading AVI files in MATLAB

I am working on extracting features from avi files using MATLAB. Every time I run the code I get an error "Exception in Reading". Code is:
cd('D:\Classified\negative-videos');
neg_files = dir('*.avi');
% compute negative files
for fileIter=1:size(neg_files,1)
tic;
movie_name = neg_files(fileIter).name;
try
[color_score__,edge_score__,spatio_score__,score__] = lg_model(movie_name,fps,3);
if(score__ < threshold)
true_neg = true_neg + 1 ;
end
if(score__ >= threshold)
false_pos = false_pos + 1 ;
end
fprintf('[ %d / %d ]\tFile : %s\tscore : %f\tcolor_score : %f\tspatio_score : %f\n', fileIter,size(neg_files,1),movie_name, score__,color_score__, spatio_score__);
catch ME1
fprintf('[ %d / %d ]\tFile : %s\t EXCEPTION IN READING \n', fileIter,size(neg_files,1),movie_name);
end
toc;
end
fprintf('INTERMEDIATE\ttrue pos = %d \n false pos = %d \n true neg = %d \n false neg = %d \n', true_pos,false_pos,true_neg, false_neg);
What is the problem with the above code snippet?
The stack trace is as follows:
For each of the 18 videos in my directory I get following error:
[ 1 / 18 ] File : 38-Meter High Dive Goes Wrong.avi EXCEPTION IN READING
ME1 =
MException
Properties:
identifier: 'MATLAB:UndefinedFunction'
message: 'Undefined function or method 'VideoReader' for input arguments of type 'char'.'
cause: {}
stack: [3x1 struct]
Methods
ME1 =
MException
Properties:
identifier: 'MATLAB:UndefinedFunction'
message: 'Undefined function or method 'VideoReader' for input arguments of type 'char'.'
cause: {}
stack: [3x1 struct]
Methods
MException
Properties:
identifier: 'MATLAB:UndefinedFunction'
message: 'Undefined function or method 'VideoReader' for input arguments of type 'char'.'
cause: {}
stack: [3x1 struct]
Methods
Undefined function or method 'VideoReader' for input arguments of type 'char'.
3x1 struct array with fields:
file
name
line
MATLAB:UndefinedFunction
Elapsed time is 0.017901 seconds.
Apologies for not posing as a comment, but need a little more rep before I'm allowed to.
I agree with #JimInCO, it looks like you don't have VideoReader. It was first introduced in R2010b. You can try using aviread instead if you have an older version.

Shell variable name queried from Matlab has additional character

I'm working with the following script, run_test:
#!/bin/sh
temp=$1;
cat <<EOF | matlab
[status name] = unix('echo $temp');
disp(name);
% some Matlab code
test_complete = 1;
save(name)
exit
EOF
I want to pass a name to the script, run some code then save a .mat file with the name that was passed. However, there is a curious piece of behavior:
[energon2] ~ $ ./run_test 'run1'
Warning: No display specified. You will not be able to display graphics on the screen.
< M A T L A B (R) >
Copyright 1984-2010 The MathWorks, Inc.
Version 7.12.0.635 (R2011a) 64-bit (glnxa64)
March 18, 2011
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
>> >> >> >> run1
>> >> >> >> >>
[energon2] ~ $ ls *.mat
run1?.mat
There is a "?" at the end of the file name when it's saved, but not when displayed on command line. This is acceptable for my needs, but a bit irritating to not know why it's occurring. Any explanation would be appreciated.
Edits, solution:
Yuk was correct below in the underlying cause and the use of save('$temp'). I'm now using the following script
#!/bin/sh
temp=$1;
cat <<EOF | matlab
% some Matlab code
test_complete = 1;
save('$temp')
exit
EOF
Thanks for the help.
You name variable has end-of-line as the last character. When you run echo run1 in unix this command display run1 and then "hit enter". In your script all the output of echo are saved to the name variable.
You can confirm it with the following:
>> format compact
>> [status, name] = unix('echo run1')
status =
0
name =
run1
>> numel(name)
ans =
5
>> int8(name(end))
ans =
10
>> int8(sprintf('\n'))
ans =
10
Apparently this character can be a part of a file name in unix, but shell displays it as ?.
Can't you do save($temp) instead?
EDIT: See my comments below for correction and more explanation.