Unformatted text preview:

1 library()234 output = function(args) function(args) command args5 function(args) command args title ‘plot title’ title(‘plot title’) title(plot_title)6 [r, c] = size(A); r cdims = size(A); dimsr = size(A, 1); c = size(A, 2); >> r = size(A, 1) r = 4 >> r = size(A, 1);7 >>8 >> A A = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 19 .m myscript.m.mdiarydiary diaryfile diaryfilediary diary on diary offquit10 >> a = [1 2 3] a = 1 2 3 >> b = [ 4 5 6 ]' b = 4 5 6 >> c = [a ; 8:10] c = 1 2 3 8 9 1011 >> d = [b (5:0.25:6)'] ??? Error using ==> horzcat All matrices on a row in the bracketed expression must have the same number of rows. >> d = [b (9:-2:5)'] d = 4 9 5 7 6 5 >> ones(2) ans = 1 1 1 1 >> zeros(2,3) ans = 0 0 0 0 0 012 >> eye(2) ans = 1 0 0 1 >> eye(2,4) ans = 1 0 0 0 0 1 0 0 >> rand(size(c)) ans = 0.4565 0.8214 0.6154 0.0185 0.4447 0.7919 A = 1 4 7 10 2 5 8 11 3 6 9 1213 B = reshape(A,2,6) B = 1 3 5 7 9 11 2 4 6 8 10 12 B = reshape(A,2,[]) B = 1 3 5 7 9 11 2 4 6 8 10 12 >> reshape(1:12,3,2,2) ans(:,:,1) = 1 4 2 5 3 6 ans(:,:,2) = 7 10 8 11 9 1214 >> B = reshape(1:6,[3 1 2]) B(:,:,1) = 1 2 3 B(:,:,2) = 4 5 6 >> C = squeeze(B) C = 1 4 2 5 3 615 () []A(1,2) A[1,2]A[,1]: A(:,1)>> A([1 3 3 2],:) ans = 8 1 6 4 9 2 4 9 2 3 5 716 A[4,4] <- 10>> A A = 8 1 6 3 5 7 4 9 2 >> A(4,4) = 10 A = 8 1 6 0 3 5 7 0 4 9 2 0 0 0 0 1017 load>> load furnace.txt .mat–ascii –matload>> load all a b c a b call.mat>> load all18 >> save allfile allfile.mat>> save furnacefile furnace furnacefile.mat>> save furnacetxt.txt furnace –ascii19 >> A = magic(3) A = 8 1 6 3 5 7 4 9 2 >> B B = 1 4 7 2 5 8 3 6 9 >> A * B ans = 28 73 118 34 79 12420 28 73 118 A %*% B>> A .* B ans = 8 4 42 6 25 56 12 54 18 ./ .\ .^>> (1:3) * (1:3) ??? Error using ==> * Inner matrix dimensions must agree. >> (1:3) * (1:3)' ans = 14 A / B A * inv(B) A \ Binv(A) * B21 >> angle = pi*(0:1/4:1) angle = 0 0.7854 1.5708 2.3562 3.1416 >> sin(angle) ans = 0 0.7071 1.0000 0.7071 0.000022 >> help help HELP On-line help, display text at command line. HELP, by itself, lists all primary help topics. Each primary topic corresponds to a directory name on the MATLABPATH. "HELP TOPIC" gives help on the specified topic. The topic can be a command name, a directory name, or a MATLABPATH relative partial pathname (see HELP PARTIALPATH). If it is a command name, HELP displays information on that command. If it is a directory name, HELP displays the Table-Of-Contents for the specified directory. For example, "help general" and "help matlab/general" both list the Table-Of-Contents for the directory toolbox/matlab/general. For tips on creating help for your m-files 'type help.m'. See also LOOKFOR, WHAT, WHICH, DIR, MORE.23 >> lookfor regress LEVERAGE Regression diagnostic. REGRESS Multiple linear regression using least squares. REGSTATS Regression diagnostics for linear models. RIDGE Ridge regression. ROBUSTFIT Robust linear regression STEPWISE Interactive tool for stepwise regression. TREEDISP Show classification or regression tree graphically. TREEFIT Fit a tree-based model for classification or regression.24 >> type mean.m function y = mean(x,dim) %MEAN Average or mean value. % For vectors, MEAN(X) is the mean value of the elements in X. For % matrices, MEAN(X) is a row vector containing the mean value of % each column. For N-D arrays, MEAN(X) is the mean value of the % elements along the first non-singleton dimension of X. % % MEAN(X,DIM) takes the mean along the dimension DIM of X. % % Example: If X = [0 1 2 % 3 4 5] % % then mean(X,1) is [1.5 2.5 3.5] and mean(X,2) is [1 % 4] % % See also MEDIAN, STD, MIN, MAX, COV. % Copyright 1984-2002 The MathWorks, Inc. % $Revision: 5.17 $ $Date: 2002/06/05 17:06:39 $ if nargin==1, % Determine which dimension SUM will use dim = min(find(size(x)~=1)); if isempty(dim), dim = 1; end y = sum(x)/size(x,dim); else y = sum(x,dim)/size(x,dim); end25 .m.m.m script.m.m%mean.m.m.mmean mean.mfunction output = funname(arg1, arg2, arg3) % One line description of the function. % Detailed descriptions. The first block % of lines starting with % characters is26 % the output when help funname is called. % The first line of this comment block is % used by the lookfor command. function code function [product, quotient] = proddiv(x, y) % Calculates product and quotient of two numbers % proddiv(x, y) returns x*y and x/y. product = x*y; quotient = x/y; >> proddiv(5,2) ans = 1027 >> pr = proddiv(5,2) pr = 10 >> [pr, qu] = proddiv(5,2) pr = 10 qu = 2.5000 fact = 1; for i = 1:10 fact = fact * i; end28 if condition1 (commands if condition1 is true) elseif condition2 (commands if condition2 is true else (commands if none of the conditions is true) end >> A = magic(3); >> B = reshape(1:9,3,3); >> C = magic(4);29 >> try z = A*B; catch z = nan; disp('A and B are not conformable') end >> z z = 28 73 118 34 79 124 28 73 118 >> try z = A*C; catch z = nan; disp('A and C are not conformable') end A and C are not conformable >> z z =


View Full Document

HARVARD STAT 335 - Matlab

Documents in this Course
Load more
Download Matlab
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Matlab and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Matlab 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?