Wrap the assignments with str2double
:
minVal = str2double (arg_list{2});
maxVal = str2double (arg_list{3});
There isn't type cast between string and numerical types, that is why your attempt with int32
have failed.
Question
I am trying to pass the values for xlim and ylim into my octave script as command line arguments. What I curently have is:
arg_list = argv ();
filename = arg_list{1};
minVal = arg_list{2};
maxVal = arg_list{3};
if (minVal >= maxVal)
disp(["min (" minVal ") must be less than max (" maxVal ")"]);
else
%prepare plot
plot(x,y);
xlim([minVal maxVal]);
ylim([minVal maxVal]);
endif
I call the script form a linux terminal like this:
for f in ./AllValues/Acceleration*.csv; do
echo "Processing file: $f";
if echo "$f" | egrep -q "High" ; then
./calc.m $f 0 50;
else
./calc.m $f 0 20;
fi
done
When the min value is 0, the xlim and ylim commands are ignored and the auto-values are used. When I try to set another value, eg. ./script.m file.csv 7 20
, the test fails and I get the output min (7) must be less than max (20)
.
I tried to cast the arguments to int32:
minVal = int32(arg_list{2});
maxVal = int32(arg_list{3});
but that generates an error when trying to set the xlim and ylim, even with a 0 value for min.
I also tried to surround the arguments in single or double quotes:
./script.m file.csv '7' '20'
./script.m file.csv "7" "20"
but that did not change anything.
Any ideas what's wrong with my script?
Solution
Wrap the assignments with str2double
:
minVal = str2double (arg_list{2});
maxVal = str2double (arg_list{3});
There isn't type cast between string and numerical types, that is why your attempt with int32
have failed.