2+2 ans = 4 2+2*3 ans = 8 a=2; a=2 a = 2 b=[1 2 7]; b b = 1 2 7 b' ans = 1 2 7 b b = 1 2 7 b' ans = 1 2 7 c=[1 2 3; 4 5 6; 7 8 9] c = 1 2 3 4 5 6 7 8 9 c c = 1 2 3 4 5 6 7 8 9 c' ans = 1 4 7 2 5 8 3 6 9 d=zeros(5,5) d = 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 e=zeros(3,4) e = 0 0 0 0 0 0 0 0 0 0 0 0 ones(5,7) ans = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 e=zeros(7) e = 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 eye(3) ans = 1 0 0 0 1 0 0 0 1 eye(7) ans = 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 eye(3,2) ans = 1 0 0 1 0 0 a=rand(5) a = 0.8147 0.0975 0.1576 0.1419 0.6557 0.9058 0.2785 0.9706 0.4218 0.0357 0.1270 0.5469 0.9572 0.9157 0.8491 0.9134 0.9575 0.4854 0.7922 0.9340 0.6324 0.9649 0.8003 0.9595 0.6787 a=rand(10,1) a = 0.7577 0.7431 0.3922 0.6555 0.1712 0.7060 0.0318 0.2769 0.0462 0.0971 sort(a) ans = 0.0318 0.0462 0.0971 0.1712 0.2769 0.3922 0.6555 0.7060 0.7431 0.7577 a=rand(7,7) a = 0.8235 0.7655 0.7547 0.9597 0.6991 0.8407 0.2511 0.6948 0.7952 0.2760 0.3404 0.8909 0.2543 0.6160 0.3171 0.1869 0.6797 0.5853 0.9593 0.8143 0.4733 0.9502 0.4898 0.6551 0.2238 0.5472 0.2435 0.3517 0.0344 0.4456 0.1626 0.7513 0.1386 0.9293 0.8308 0.4387 0.6463 0.1190 0.2551 0.1493 0.3500 0.5853 0.3816 0.7094 0.4984 0.5060 0.2575 0.1966 0.5497 sort(a) ans = 0.0344 0.1869 0.1190 0.2238 0.1386 0.1966 0.2511 0.3171 0.4456 0.1626 0.2551 0.1493 0.2435 0.3517 0.3816 0.4898 0.2760 0.3404 0.2575 0.2543 0.4733 0.4387 0.6463 0.4984 0.5060 0.5472 0.3500 0.5497 0.6948 0.7094 0.6551 0.5853 0.6991 0.8143 0.5853 0.8235 0.7655 0.6797 0.7513 0.8909 0.8407 0.6160 0.9502 0.7952 0.7547 0.9597 0.9593 0.9293 0.8308 sort(a,2) ans = 0.2511 0.6991 0.7547 0.7655 0.8235 0.8407 0.9597 0.2543 0.2760 0.3404 0.6160 0.6948 0.7952 0.8909 0.1869 0.3171 0.4733 0.5853 0.6797 0.8143 0.9593 0.2238 0.2435 0.3517 0.4898 0.5472 0.6551 0.9502 0.0344 0.1386 0.1626 0.4456 0.7513 0.8308 0.9293 0.1190 0.1493 0.2551 0.3500 0.4387 0.5853 0.6463 0.1966 0.2575 0.3816 0.4984 0.5060 0.5497 0.7094 help sort SORT Sort in ascending or descending order. For vectors, SORT(X) sorts the elements of X in ascending order. For matrices, SORT(X) sorts each column of X in ascending order. For N-D arrays, SORT(X) sorts the along the first non-singleton dimension of X. When X is a cell array of strings, SORT(X) sorts the strings in ASCII dictionary order. Y = SORT(X,DIM,MODE) has two optional parameters. DIM selects a dimension along which to sort. MODE selects the direction of the sort 'ascend' results in ascending order 'descend' results in descending order The result is in Y which has the same shape and type as X. [Y,I] = SORT(X,DIM,MODE) also returns an index matrix I. If X is a vector, then Y = X(I). If X is an m-by-n matrix and DIM=1, then for j = 1:n, Y(:,j) = X(I(:,j),j); end When X is complex, the elements are sorted by ABS(X). Complex matches are further sorted by ANGLE(X). When more than one element has the same value, the order of the elements are preserved in the sorted result and the indexes of equal elements will be ascending in any index matrix. Example: If X = [3 7 5 0 4 2] then sort(X,1) is [0 4 2 and sort(X,2) is [3 5 7 3 7 5] 0 2 4]; See also ISSORTED, SORTROWS, MIN, MAX, MEAN, MEDIAN, UNIQUE. Overloaded methods: cell/sort ordinal/sort Reference page in Help browser doc sort z=zeros(4,3,2) z(:,:,1) = 0 0 0 0 0 0 0 0 0 0 0 0 z(:,:,2) = 0 0 0 0 0 0 0 0 0 0 0 0 y=zeros(2,2,2,2) y(:,:,1,1) = 0 0 0 0 y(:,:,2,1) = 0 0 0 0 y(:,:,1,2) = 0 0 0 0 y(:,:,2,2) = 0 0 0 0 a=eye(5) a = 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 imagesc(a) a=eye(500); imagesc(a); a=eye(50); imagesc(a); imagesc(eye(50)+eye(50)') imagesc(eye(50)+flipud(50)') imagesc(eye(50)+flipud(eye(50))) b=rand(50); imagesc(b) colormap('gray') b=rand(10); b b = Columns 1 through 7 0.3526 0.8574 0.8065 0.5678 0.8999 0.6382 0.4911 0.5934 0.0844 0.6014 0.2990 0.5241 0.3430 0.2783 0.5852 0.9721 0.7896 0.2561 0.1202 0.2165 0.3398 0.6677 0.0315 0.7992 0.8866 0.1778 0.7862 0.2873 0.6480 0.8354 0.0496 0.4468 0.7061 0.7231 0.1709 0.4334 0.8357 0.2832 0.8160 0.8314 0.2788 0.3993 0.1398 0.0499 0.6535 0.0983 0.0348 0.5824 0.6976 0.7519 0.5459 0.4897 0.8596 0.7578 0.4210 0.2037 0.2418 0.9432 0.9729 0.0276 0.9571 0.0921 0.6663 0.6505 0.3215 0.7485 0.8992 0.3429 0.0240 0.4431 Columns 8 through 10 0.4333 0.7753 0.3801 0.1752 0.6077 0.2133 0.1932 0.9480 0.3829 0.6164 0.0596 0.0297 0.2690 0.2687 0.4723 0.5597 0.9867 0.3334 0.9448 0.7722 0.9758 0.7145 0.4754 0.5554 0.6792 0.6809 0.8463 0.9594 0.4169 0.4081 b=rand(5) b = 0.4620 0.7390 0.6463 0.1567 0.8896 0.8263 0.5674 0.3796 0.4716 0.1096 0.9912 0.9688 0.4766 0.5430 0.4378 0.5239 0.8245 0.9119 0.0597 0.2802 0.9254 0.9596 0.0149 0.6580 0.9852 imagesc(b) b(1,1)=0; imagesc(b) b(1,3)=0; imagesc(b) b(2,3)=0; b(3,3)=0; b(:,3)=0; imagesc(b) b(3,:)=0; imagesc(b) for i=1:5 b(i,1)=0; end imagesc(b) b(:,:)=0 b = 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 b=rand(5) b = 0.6088 0.8370 0.1210 0.4742 0.1254 0.2537 0.8333 0.8564 0.8350 0.1323 0.1326 0.2037 0.8998 0.4694 0.8705 0.5450 0.5444 0.2179 0.4138 0.6030 0.8278 0.8749 0.0770 0.5027 0.2653 imagesc(b) b(2:4,2:4)=1; imagesc(b) colormap('jet') a=rand(1000); b=1-a; b=round(a); imagesc(b) z=[b;b;1-b]; imagesc(z) size(z) ans = 3000 1000 d(:,:,1)=b; {??? Subscripted assignment dimension mismatch. } d=zeros(1000,1000,3); d(:,:,1)=b; d(:,:,2)=b; d(:,:,3)=1-b; imagesc(d) d(:,:,1)=ones(1000); d(:,:,2)=ones(1000); d(:,:,3)=zeros(1000); imagesc(d) a=rand(100,100,3); imagesc(a) a(:,:,3)=0; imagesc(a) diary off