;; Assignment >> v = 10; >> v >> v = [2 3 4]; >> v ;; Reason for a string: >> '3' >> 3 >> '3'+45 >> '{.'+0 >> disp('P(1,2)=10'); >> P=[1 2 3; 4 5 6; 7 8 9]; >> i=2; >> j=1; >> disp(strcat('P(',num2str(i),',',num2str(j),')=',num2str(P(i,j)))); ;; P(2,1)=4; >> [a b c] >> a=1; >> b=2; >> c=3; >> [a b c] >> s = ['a' 'b' 'c'] >> s(1) >> s(2) >> f='2*x'; >> eval(f); >> x = 2; >> eval(f); ;; Vectors of numbers >> linspace(0,9.34,7) ;; Booleans >> 123 == 123 >> 123 == 405 >> 123 ~= 405 >> 123 < 405 >> 123 <= 405 >> 405 <= 405 >> 123 > 405 >> 3 < 4 | 6 < 5 >> 3 < 4 & 6 < 5 >> 3 < 4 & 5 < 6 >> 1 < 2 & 2 < 3 & 3 < 4 >> if 3 < 4 disp('1'); else disp('2'); end >> if 3 < 4 >> disp('1'); >> else >> disp('2'); >> end ;; Assume the name of the vector is v >> if v(1) > v(2) v=[v(2) v(1)]; end ;; Plots >> x = linspace(0,2*pi,100); >> plot(x,sin(x)); >> hold on; >> plot(x,cos(x),'color',[1 .5 0]); >> x = '1:1:m' >> m = 10; >> sum(eval(x)); >> m = 20; >> sum(eval(x)); ;; Sums >> m = input('>'); >> x = 1:1:m; >> s1 = sum(x); >> s2 = sum(x.^2); ;; A population model ;; 650000000 in 2006, grows at 1% annually ;; 650000000(1.01) -> 2007 ;; 650000000(1.01)(1.01) -> 2008 ;; 650000000(1.01)^(t-2006) -> year t ;; Use .^ if t is a vector >> 650000000(1.01).^(t-2006) ;; When is (1.01)^(t-2006) = 2? ;; When is (t-2006)*log(1.01) = log(2)? ;; When is (t-2006) = log(2)/log(1.01)? ;; So t = 2006 + log(2)/log(1.01) = 2006 + 69 <- doubles every 69 years