>> 1+2
ans = 3
>> 3-1
ans = 2
>> 4*5
ans = 20
>> 5/2
ans = 2.5000
>> mod(10, 3)
ans = 1
>> abs(-2)
ans = 2
>> sin(pi)
ans = 1.2246e-16
>> cos(2*pi)
ans = 1
>> e
ans = 2.7183
>> log(e)
ans = 1
>> log10(1000)
ans = 3
>> c1=i
c1 = 0 + 1i
>> c2=1
c2 = 1
>> c1+c2
ans = 1 + 1i
>> e^(pi * i)
ans = -1.0000e+00 + 1.2246e-16i
>> exp(pi * i)
ans = -1.0000e+00 + 1.2246e-16i
>> A = [1, 2, 3; 4, 5, 6; 7, 8, 9]
A =
1 2 3
4 5 6
7 8 9
>> B = [2, 3, 5; 7, 11, 13; 17, 19, 23]
B =
2 3 5
7 11 13
17 19 23
>> A*B
ans =
67 82 100
145 181 223
223 280 346
>> A' # A transpose
ans =
1 4 7
2 5 8
3 6 9
>> columns(A)
ans = 3
>> rows(A)
ans = 3
>> A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
A =
1 2 3 4 5 6 7 8 9
>> reshape(A, 3, 3)
ans =
1 4 7
2 5 8
3 6 9
>> v1 = [-1, 2, 4]
v1 =
-1 2 4
>> norm(v1)
ans = 4.5826
>> v2 = [-1; 2; 4]
v2 =
-1
2
4
>> conv([1, 2, -2],[3, 4, -2])
ans =
3 10 0 -12 4
>> x = [1, 2, 3, 4, 5]
x =
1 2 3 4 5
>> y = [1, 4, 9, 16, 25]
y =
1 4 9 16 25
>> plot(x,y)
>> x = [pi*0, pi*0.25, pi*0.5, pi*0.75, pi, pi*1.25, pi*1.5, pi*1.75, pi*2, pi*2.25, pi*2.5]
x =
Columns 1 through 10:
0.00000 0.78540 1.57080 2.35619 3.14159 3.92699 4.71239 5.49779 6.28319 7.06858
Column 11:
7.85398
>> plot(x, sin(x))
Smoother Sine Curve Using linspace
>> x = linspace(0, 2*pi, 12)
x =
Columns 1 through 10:
0.00000 0.57120 1.14240 1.71360 2.28479 2.85599 3.42719 3.99839 4.56959 5.14079
Columns 11 and 12:
5.71199 6.28319
>> plot(x,sin(x))
xlabel("something")
ylabel("something else")
Keep and Add to Current Plot
hold on
legend("sin", "cos")
title("My Plots")
Create Image from Matrix A
imagesc(A)
Same Thing, but Grayscale
imagesc(A), colorbar, colormap gray
help plot
Get Information About Audio File
>> audioinfo("sounds/Carillion.wav")
ans =
scalar structure containing the fields:
Filename = Carillion.wav
CompressionMethod =
NumChannels = 1
SampleRate = 44100
TotalSamples = 619306
Duration = 14.043
BitsPerSample = 16
BitRate = -1
Title = 120LUTH3
Artist =
Comment =
[y, fs] = audioread("sounds/Carillion.wav")
>> player = audioplayer(y,fs)
>> play(player)
>> disp("one plus one is")
one plus one is
>> disp(1+1)
2
x = 5
>> printf("x is %d\n",x)
x is 5
>> if (1==1)
disp("good")
endif
good
>> for i = [1,2,3]
disp(i)
endfor
>> while true,
disp("hi");
end;
hi
hi
hi
...
>> clear x
>> function foo
disp("hi")
endfunction
>> foo
hi
>> function add(a, b)
disp(a+b)
endfunction
>> add(4, 5)
9
With Arguments and Return Value
>> function sum = add(a, b)
sum = a + b
endfunction
>> c = add(3, 4)
sum = 7
c = 7
pwd
cd '/home/neil/'
ls '/home/neil'
load('somefile.dat')
Save Variable v
to a File
save hello.mat v;
Save Variable v
to a File (ASCII)
save hello.txt v -ascii;
oldpager = PAGER('/dev/null');
oldpso = page_screen_output(1);
oldpoi = page_output_immediately(1);
% Call function here
PAGER(oldpager);
page_screen_output(oldpso);
page_output_immediately(oldpoi);
Show All Variables in Current Workspace
who
Great contribution, thank you!