Matlab Quick Reference: General
My Matlab quick reference: General notes
Mini random lottery number generator.
1 2 3 4 | k = randperm(49); n = k(1:7) n = 37 13 6 5 33 26 41 |
Difference Between && and &
&& is a short-circuit version of the & logical operator meaning when entering
1 | a && b |
Matlab first evaluates a and if it is wrong, terminates immediately without evaluating b
Example:
1 | if ( (x > 0) && (1/x < 3) ) % 1/x will never be evaluated with x = 0 |
Single quote into a string
1 2 3 | string = [ 'Cindy' char(39) 's exquisite something ...'] string = Cindy's exquisite something ... |
ASCII table: http://www.neurophys.wisc.edu/www/comp/docs/ascii.html
Mean without counting zeros
1 2 | x = [ 1 2 3 0 0]; u = mean( x(x~=0) ); |
Remove Row or Column
To remove the Nth Row, use
1 | X(N, :) = []; |
To remove Mth Column, use
1 | X(:, M) = []; |

