Reputation: 597
So I am working on an Octave script (I am relatively inexperienced with the language), and I am trying to open two csv files who's names I pass to my script as command line arguments. Here is my script:
#!/usr/bin/env octave
function plotregs(fig, regs)
figure(fig);
title('Foo');
xlabel('Value');
ylabel('Cycle #');
grid on;
plot(rows(regs(:, 1)), regs(:, 1),
rows(regs(:, 2)), regs(:, 2),
rows(regs(:, 3)), regs(:, 3),
rows(regs(:, 4)), regs(:, 4),
rows(regs(:, 5)), regs(:, 5),
rows(regs(:, 6)), regs(:, 6),
rows(regs(:, 7)), regs(:, 7),
rows(regs(:, 8)), regs(:, 8));
legend('A', 'B', 'C', 'D', 'E', 'F', 'H', 'L');
endfunction
args = argv ();
filename = strcat(cellstr(args(1)));
typeinfo filename
regs = csvread(filename);
graphics_toolkit("gnuplot");
plotregs(1, regs);
filename = strcat(cellstr(args(2)));
regs = csvread(filename);
plotregs(2, regs);
pause
And here is the output I get when I run the script:
ans = sq_string
error: dlmread: FILE argument must be a string or file id
error: called from:
error: /usr/share/octave/3.4.3/m/io/csvread.m at line 34, column 5
error: /home/tnecniv/Code/Octave/regigraph/regigraph.m at line 25, column 6
Any advice would be appreciated
Upvotes: 1
Views: 1115
Reputation: 715
The problem is that you create an executable Octave script which expects arguments yet do not provide any arguments.
First of all I would start the file as
#!/usr/bin/octave -qf
Then one could run the script as
$ ./myscript.sh datafile1.csv datafile2.csv
But in my opinion argv() behaves a bit strange, because when no arguments are given to -say myscript.sh-, it returns the filename of the executing script, but when one or more arguments are given it contains the arguments only.
You can refer to Section 2.6 of the documentation for "Executable Octave Programs".
Upvotes: 3