Octave commands
List variables available in memorywho %this is a commentChange and display working directory
whos %provides class details
cd directory_nameManipulate data structures:
pwd
Display the value of a variablex.a = 1; x.b = [1, 2; 3, 4]; x.c = "string";
disp(x)Loop over a list of files
csvfiles = dir("*.csv")Creating character arrays
for file= csvfiles'
fprintf(1,'Doing something with %s\n',file.name)
end
"In the MATLAB® computing environment, all variables are
arrays, and strings are of type char
(character
arrays)."
Reading data from an Excel or CSV file
The test statistics I wanted to use loads data from an Excel file but this returned the error :" 'xlsread' undefined ". Reading excel file is provided by the IO package which is not installed by default. The package is available in the Debian repository under "octave-io" , with the description "This package [...] contains functions to [...] read Excel spreadsheet (xlsread) and OpenDocument spreadsheet (odsread)." It is based on Apache POI. Load the package an try to read a file:pkg load io;xlsread returns an error "Detected XLS interfaces: None." This forum post recommends to load the java and windows packages as well. Those packages are not available in the Debian repositories.
data=xlsread('file_name.xls');
I decided to convert the Excel file to csv and use csvread instead.
The script now gives the same output as on a windows machine running Matlab.
Warning: possible Matlab-style short-circuit operator
Short-circuit boolean operators explains that:"MATLAB has special behavior that allows the operators ‘&’ and ‘|’ to short-circuit when used in the truth expression forI wonder why it is strongly discouraged.if
andwhile
statements. The Octave parser may be instructed to behave in the same manner, but its use is strongly discouraged." [...]
"To obtain short-circuit behavior for logical expressions in new programs, you should always use the ‘&&’ and ‘||’ operators."I replaced "|" by "||" in the code.
No comments:
Post a Comment