install and use octave on pi [raspberrypi]

install octave on raspberrypi:
sudo apt-get install octave -y

make a directory for your scripts and functions and link the path to octave:
cd
mkdir MyOctaveFiles
path(path, "/home/pi/MyOctaveFiles")
savepath

start octave in terminal:
octave

plot a sombrero:
sombrero

name the axis of the plotted sombrero:
xlabel("x-axis")
ylabel("y-axis")
zlabel("z-axis")

give it a title:
title("A wonderfull sombrero")

exit octave in terminal:
exit

some help:
use ‘;’ at the end for no output
use ‘arrow up button’ for the latest command
use ‘%’ for comments

examples:
———

plot 2d:
x = linspace(0, 2*pi, 100);
y = sin(x);
plot(x, y);

work with struct arrays:
person.name = 'Testuser';
person.country = 'Germany';
person.age = 90;
person.gender = 'male';

person.age=31;
person.age
person
fieldnames(person)

polynominals:
x = linspace(-3,3);
p = [5,0,-10];
y=polyval(p, x);
% that will give you an output of y=5x^2-10
plot (x,y);

two plots:
figure
x = linspace(-2*pi, 2*pi, 50);
a = sin(x);
b = cos(x);
plot(x, a);
plot(x, b);

create an example script:
nano home/pi/MyOctaveFiles/egscript.m

% this lines will be shown when you write 'help egscript'
% hihi
x = linspace(-10, 10, 50);
y = x.^2;
plot (x,y);

run the example script:
egscript

create an example function:
nano /home/pi/MyOctaveFiles/egfunction.m

function [x_med] = egfunction(x_1, x_2, x_3)
% only an example that gives back the medium
x_med=(x_1+x_2+x_3)/3.;

run the example function:
egfunction(1,2,9)

save and load workspace:
save testworkspace
load testworkspace

display variables in memory:
who()

clear all variables from memory:
clear()

usefull octave help:
http://www.gnu.org/software/octave/doc/interpreter/
http://www.gnu.org/software/octave/octave.pdf

other links:
http://wiki.octave.org/Rasperry_Pi
http://www.gomatlab.de
http://wiki.octave.org/FAQ

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s