octave:octave
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
octave:octave [2008/06/25 09:56] – created deva | octave:octave [2009/04/23 13:54] (current) – deva | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | =====Octave===== | + | =====Octave |
- | ====if then else end==== | + | ====Installing packages==== |
- | < | + | Fetch the package files from [[http:// |
- | a = 1 | + | Then create (or add to) the file ~/.octaverc the following content: |
+ | <code matlab> | ||
+ | addpath(genpath(' | ||
+ | </ | ||
+ | And run '' | ||
+ | Now the package should be available. | ||
+ | |||
+ | ====plotting==== | ||
+ | <code matlab> | ||
+ | h = [1, | ||
+ | plot(h); | ||
+ | xlabel(" | ||
+ | print(" | ||
+ | </ | ||
+ | This code plots a a vector with a label on the x-axis, and exports it to a pdf file. | ||
+ | |||
+ | <code matlab> | ||
+ | h=wavread(' | ||
+ | hfft=abs(fft(h)); | ||
+ | semilogx(hfft(1: | ||
+ | </ | ||
+ | This code loads an audiofile, and plots its frequency spectrum on a logartihmical scale. | ||
+ | |||
+ | ====function==== | ||
+ | <code matlab> | ||
+ | function retval = myfunction(param1, | ||
+ | retval = param1 + param2; | ||
+ | end; | ||
+ | </ | ||
+ | |||
+ | ====strings==== | ||
+ | <code matlab> | ||
+ | mystring = 'hello world'; | ||
+ | sizeof(mystring) % get length of string | ||
+ | |||
+ | mystrilyng2 = [ mystring, ' | ||
+ | |||
+ | </ | ||
+ | sizeof on works in octave. in matlab the length of a string cannot be obtained! | ||
+ | |||
+ | ====string array==== | ||
+ | <code matlab> | ||
+ | myemptyarray = {}; % create empty string array. | ||
+ | |||
+ | myarray = { ' | ||
+ | myarray(1) % prints ' | ||
+ | myarray(3) = ' | ||
+ | |||
+ | sizeof(myarray) % get number of elements | ||
+ | sizeof(myarray(1)) %get length of first string | ||
+ | |||
+ | % Iterate strings in string array | ||
+ | for str = myarray | ||
+ | disp(str) | ||
+ | end | ||
+ | |||
+ | </ | ||
+ | Note: Arrays are 1-based, not 0-based as they usually are in real programming languages. | ||
+ | Note: sizeof is an octave-only function. size can be used to get the array size in matlab. | ||
+ | |||
+ | ====if then else==== | ||
+ | < | ||
+ | a = 1; | ||
if a == 1 | if a == 1 | ||
+ | "a is one" | ||
end; | end; | ||
+ | |||
+ | if a == 2 | ||
+ | "a is two" | ||
+ | else | ||
+ | "a is not two" | ||
+ | end; | ||
+ | </ | ||
+ | |||
+ | ====for while==== | ||
+ | <code matlab> | ||
+ | list = 1:10 | ||
+ | |||
+ | for i = list | ||
+ | i | ||
+ | end; | ||
+ | |||
+ | a = 1; | ||
+ | while a < 11 | ||
+ | a | ||
+ | a = a + 1; | ||
+ | end; | ||
+ | </ | ||
+ | |||
+ | ====switch case==== | ||
+ | <code matlab> | ||
+ | yesno = " | ||
+ | |||
+ | switch yesno | ||
+ | case {" | ||
+ | value = 1; | ||
+ | case {" | ||
+ | value = 0; | ||
+ | case " | ||
+ | value = 42; | ||
+ | otherwise | ||
+ | error (" | ||
+ | endswitch | ||
</ | </ | ||
+ | Note: In matlab the '' | ||
====Links==== | ====Links==== |
octave/octave.1214380614.txt.gz · Last modified: 2008/06/25 09:56 by deva