Many Matlab commands (e.g., those creating graphs) accept the variables as arrays.
Numerical array operations are simple to perform. Here are some examples:
x=1:.2:2
y=2*x.^4+x.* sin(x)/4./(1+x)
plot(x,y)
x=[1 3 4 6 8 2]
len=length(x)
y=x(3)
z=x(2:5)
s=x(end-2:end)
r=x([1 3 3 2 4 2])
t=x(6:-1:1)
find
for
more uses (e.g., locating the 'first' or 'last' match).
>> x=[2,3,4,3,5,2] x = 2 3 4 3 5 2 >> x(x>3) % subarray of entries > 3 ans = 4 5 >> find(x>3) % indexes of entries > 3 ans = 3 5 >> x(x==4) % subarray of entries equal to 4 ans = 4 >> x(x==2) % subarray of entries equal to 2 ans = 2 2 >> x(isprime(x)) % subarray of prime entries ans = 2 3 3 5 2 >> find(isprime(x)) % indexes of prime entries in x ans = 1 2 4 5 6 >> x(find(isprime(x))) % same as x(isprime(x)) ans = 2 3 3 5 2
t(7:8)=[9 20]
t(3)=[]
M=zeros(50,100,10);
U= |
|
U=[1 2 5; 3 4 0]
U(1,:)=ones(1,3)
A=U(:,1:2)
B=A'
(the non-conjugate transpose is given by .'; it differs from the
above only if the matrix has non-real entries)
C=A * B
A\C
C/B
D=C^3
E=C^(-1)
E*C