Octave

From Steak Wiki
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Tips on GNU Octave

  • Get some books
  • It's inefficient on the CPU, so use it for fun and prototyping.

argv

# NOTE: numbers passed into argv are treated as (ascii) char
# must convert with str2num, or some other
e.g. (call script with ./script 20
#!/usr/bin/octave

arg_list = argv();
HOWLONG=arg_list{1}

# NOTE: numbers passed into argv are treated as (ascii) char
# which means 0 is around 40 in binary.
# must convert with str2num, or some other
# cast() will not fix this (as it casts the binary)

display("How long is: ")
class(HOWLONG) 
news2 = str2num(HOWLONG)
display("news2 is now: ")
class(news2)


if loop

#don't forget quotes on numbers here
#if  HOWLONG == "1"
#       SQLQUERYNUM = 288;
#elseif HOWLONG == "3"
#       SQLQUERYNUM = 288 * 3;
#elseif HOWLONG == "7"
#       SQLQUERYNUM =  288 * 7;
#elseif HOWLONG == "14"
#       SQLQUERYNUM = 288 * 14;
#else
#display("incorrect time to search")
#display("Try, 1, 3, 7, 14")
#exit();
#en


sprintf

  1. basic sprintf (req's quotes)
  2. val1="test"
  3. val2="something"
  4. sprintf("%s%s",val1,val2)
  5. if you want to assign to variable, sprintf(variable,"%s%s",val1,val2)
  6. won't work, but ofc
  7. newvar = sprintf("%s%s",val1,val2)
  8. will

call function with parenthesis or not

  1. dynamically generate print filename at runtime
  2. https://www.mathworks.com/matlabcentral/answers/148-how-do-i-dynamically-generate-a-file-name-for-save-in-matlab
  3. essentially, if you myvar = sprintf(something...)
  4. you have to print(myvar)
  5. not print myvar
  6. so parenthesis are required (but they are not always required for e.g. print)

invert Y axis

  1. display(p(:,2)) (all times)
  2. display(p(:,1)) (all values)
  3. vals = p(:,1)
  4. EDIT: the below was a bug.
  5. it appears you can't invert the (p(:,1)) in plot, with either common commands used to invert Y axis.
  6. these cmds are: axis(ij) after plot, as well as set(gca,'YDir','reverse');, and plot (flipud(p(:, 2)), p(:, 1)) (this latter one inverts only the X axis, not Y
  7. so instead, send it to a new variable
  8. flipud(vals)
  9. EDIT: this isn't what I want to do. it flips the array upside down. instead, I want the high end
  10. of the y axis to be at the bottom, and the low numbers to be at the top.
  11. https://savannah.gnu.org/bugs/?47223
  12. I dug into the bug tracker, and also dl'd source code. looks like i have an old version
  13. installing debian 10 resolved this (could also have used backports in stretch).

Database Package with Devuan 9

Devuan ascii has octave 4.0. ascii backports has 4.4, but not octave-struct (without breaking in devuan). Must migrate to Devuan Beowulf to get full octave 4.4.