【文章內(nèi)容簡(jiǎn)介】
s and Matrixes,Array: ex. 1x6 array A = [1 2 3 4 5 6]。 or A = [1, 2, 3, 4, 5, 6]。 Matrix: ex. 2x3 matrix B = [1 2 3。 4 5 6。 7 8 9]。 or B = [1 2 3 4 5 6 7 8 9]。 A(1) = ? A (6) = ? B(1,2) = ? B (1,:) = ? B(:,1) = ? Examples:,11,Operations of Arrays and Matrixes,The mathematical operations of array and matrix,12,Matlab Functions,The MATLAB functions,13,Flow control selection,The ifelseifelse construction,if elseif else end,if height170 disp(’tall’) elseif height150 disp(’small’) else disp(’average’) end,14,Logical expressions,Relational operators (compare arrays of same sizes) = = (equal to) ~= (not equal) (greater than) = (greater than or equal to) Logical operators (combinations of relational operators) amp。 (and) | (or) ~ (not) Logical functions xor isempty any all,if (x=0) amp。 (x=10) disp(‘x is in range [0,10]’) else disp(‘x is out of range’) end,15,Flow control repetition,Repeats a code segment a fixed number of times,for index= end The are executed repeatedly. At each iteration, the variable index is assigned a new value from .,for k=1:12 kfac=prod(1:k)。 disp([num2str(k),’ ‘,num2str(kfac)]) end,16,Example – selection and repetition,function y=fact(n) % FACT – Display factorials of integers 1n if nargin eps error(’Input must be an integer’) end for k=1:n kfac=prod(1:k)。 disp([num2str(k),’ ’,num2str(kfac)]) y(k)=kf