A=1:25; A=reshape(A,5,5); B=reshape(1:25,5,5); A A = 1 6 11 16 21 2 7 12 17 22 3 8 13 18 23 4 9 14 19 24 5 10 15 20 25 B B = 1 6 11 16 21 2 7 12 17 22 3 8 13 18 23 4 9 14 19 24 5 10 15 20 25 clear clc A=reshape(A,5,5)'; {Undefined function or variable 'A'. } A=1:25; A=reshape(A,5,5)'; B=reshape(1:25,5,5)'; A A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 B B = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 help reshape reshape - Reshape array This MATLAB function or B = reshape(A,[m n]) returns the m-by-n matrix B whose elements are taken column-wise from A. B = reshape(A,m,n) B = reshape(A,[m n]) B = reshape(A,m,n,p,...) B = reshape(A,[m n p ...]) B = reshape(A,...,[],...) Reference page for reshape See also circshift, colon (:), permute, repmat, shiftdim, squeeze Other functions named reshape control/reshape, fixedpoint/reshape, symbolic/reshape v=1:5; sum(v) ans = 15 sum(A) ans = 55 60 65 70 75 A A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 sum(sum(A)) ans = 325 rand(3) ans = 0.8147 0.9134 0.2785 0.9058 0.6324 0.5469 0.1270 0.0975 0.9575 randi(3) ans = 3 randi(3,3) ans = 1 2 2 3 3 3 3 1 3 randi(3,3,5) ans = 3 3 3 2 1 2 3 3 1 1 1 3 2 3 1 randperm(10;5) randperm(10;5) | {Error: Unbalanced or unexpected parenthesis or bracket. } randperm(10,5) ans = 7 8 3 10 1 randperm(10,50) {Error using randperm K must be less than or equal to N. } randperm(10,10) ans = Columns 1 through 8 2 4 8 5 6 7 10 1 Columns 9 through 10 3 9 v v = 1 2 3 4 5 v(3:4) ans = 3 4 v=v*10 v = 10 20 30 40 50 v(3:4) ans = 30 40 v(10) {Index exceeds matrix dimensions. } v(3)=-8 v = 10 20 -8 40 50 v(1)=v(5) v = 50 20 -8 40 50 v=(1:5)*10; A A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 save va v A v(:)=-2 v = -2 -2 -2 -2 -2 load va v(1:3)=[9 8] {In an assignment A(I) = B, the number of elements in B and I must be the same. } v(1:3)=[9 8 6] v = 9 8 6 40 50 n=[-1 -2 -3]; v(3:end)=n v = 9 8 -1 -2 -3 v(1:2)=v(4:5) v = -2 -3 -1 -2 -3 load va A A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 A(3,2)=0 A = 1 2 3 4 5 6 7 8 9 10 11 0 13 14 15 16 17 18 19 20 21 22 23 24 25 A(1:2,[4 5])=[-1 -2;-3 -4] A = 1 2 3 -1 -2 6 7 8 -3 -4 11 0 13 14 15 16 17 18 19 20 21 22 23 24 25 A(1:3,[4 5])=[-1 -2;-3 -4] {Subscripted assignment dimension mismatch. } A(1,:)=80 A = 80 80 80 80 80 6 7 8 -3 -4 11 0 13 14 15 16 17 18 19 20 21 22 23 24 25 A(1,:)=sin(pi/3) A = 0.8660 0.8660 0.8660 0.8660 0.8660 6.0000 7.0000 8.0000 -3.0000 -4.0000 11.0000 0 13.0000 14.0000 15.0000 16.0000 17.0000 18.0000 19.0000 20.0000 21.0000 22.0000 23.0000 24.0000 25.0000 load va A A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 A(3,:)=v A = 1 2 3 4 5 6 7 8 9 10 10 20 30 40 50 16 17 18 19 20 21 22 23 24 25 A(:,1)=v A = 10 2 3 4 5 20 7 8 9 10 30 20 30 40 50 40 17 18 19 20 50 22 23 24 25 A(:,[4 5])=[v'v'] A(:,[4 5])=[v'v'] | {Error: Unexpected MATLAB expression. } A(:,[4 5])=[v' v'] A = 10 2 3 10 10 20 7 8 20 20 30 20 30 30 30 40 17 18 40 40 50 22 23 50 50 A(:,[4 5])=[v; v]' A = 10 2 3 10 10 20 7 8 20 20 30 20 30 30 30 40 17 18 40 40 50 22 23 50 50 v v = 10 20 30 40 50 v(3)=[] v = 10 20 40 50 whos Name Size Bytes Class Attributes A 5x5 200 double B 5x5 200 double ans 1x2 16 double n 1x3 24 double v 1x4 32 double v(1:3)=[] v = 50 whos Name Size Bytes Class Attributes A 5x5 200 double B 5x5 200 double ans 1x2 16 double n 1x3 24 double v 1x1 8 double A A = 10 2 3 10 10 20 7 8 20 20 30 20 30 30 30 40 17 18 40 40 50 22 23 50 50 load va A(3,2)=[] {Subscripted assignment dimension mismatch. } A(3,:)=[] A = 1 2 3 4 5 6 7 8 9 10 16 17 18 19 20 21 22 23 24 25 A(:,1:2:5)=[] A = 2 4 7 9 17 19 22 24 load va 5>9 ans = 0 5>-9 ans = 1 v v = 10 20 30 40 50 v>30 ans = 0 0 0 1 1 v1=1:5; v>v1 ans = 1 1 1 1 1 v1>v ans = 0 0 0 0 0 v1>[v v] {Error using > Matrix dimensions must agree. } v1>[-9 5 2 0 10] ans = 1 0 1 1 0 v1 v1 = 1 2 3 4 5 v~=v1 ans = 1 1 1 1 1 v!=v1 v!=v1 | {Error: Unexpected MATLAB operator. } A A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 A>25 ans = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A>10 ans = 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 A==v {Error using == Matrix dimensions must agree. } A(3,:)==v ans = 0 0 0 0 0 A(:,4)==v {Error using == Matrix dimensions must agree. } A(:,4)==v' ans = 0 0 0 0 0 A(2,:)==B(:,5)' ans = 0 0 0 0 0 A A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 A==5 ans = 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 any(A==5) ans = 0 0 0 0 1 any(v==20) ans = 1 any(v==200) ans = 0 any(any(A==5)) ans = 1 any(any(A==500)) ans = 0 all(v>60) ans = 0 all(v>-60) ans = 1 all(v>30) ans = 0 all(A==0) ans = 0 0 0 0 0 all(A==10) ans = 0 0 0 0 0 all(A>4) ans = 0 0 0 0 1 all(all(A>4)) ans = 0 all(all(A>-4)) ans = 1 v v = 10 20 30 40 50 v>40 ans = 0 0 0 0 1 v(ans) ans = 50 v(7)=-100 v = 10 20 30 40 50 0 -100 A(10,:)=v(1:5) A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 20 30 40 50 V {Undefined function or variable 'V'. } v v = 10 20 30 40 50 0 -100 find(v==30) ans = 3 find(v==300) ans = Empty matrix: 1-by-0 find(v>=30) ans = 3 4 5 A A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 20 30 40 50 load va A A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 find(A==9) ans = 17 [x y]=find(A==9) x = 2 y = 4 [x y]=find(A>9) x = 3 4 5 3 4 5 3 4 5 3 4 5 2 3 4 5 y = 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 5 [x y]=find(A>20) x = 5 5 5 5 5 y = 1 2 3 4 5 A(x,y) ans = 21 22 23 24 25 21 22 23 24 25 21 22 23 24 25 21 22 23 24 25 21 22 23 24 25 A(find(A>20)) ans = 21 22 23 24 25 A(A>20) ans = 21 22 23 24 25 diary off