FIC MATLAB 2018-2/Aula-8

De MediaWiki do Campus São José
Ir para: navegação, pesquisa

% Variáveis lógicas true True false x = 0 y = false logical(200) logical(-123) logical(1) logical(3.14) logical(0) logical([]) logical([pi 0 10]) sin([pi 0 10]) logical([pi 0 10; 1 1 0]) A = randi([0 9], 2, 3) A(3) A(1, 2) v = randi([100 199], 1, 6) v([2 4 5]) v([false true false true true false]) v([false true false true true]) v([false true false true true false false]) v([false true false true true false true]) A A([true true false; false true false]) A([true true false false true false]) [true true false; false true false] [true true false false; true false] [true true false; false true false] [true true false false true false] v v([false true false true true false]) v([0 1 0 1 1 0]) v(logical([0 1 0 1 1 0])) v([1 1 1 1 1 1]) 4 < 6 4 >= 6 doc format % Operadores relacionais 5 == 5 q = 1000 q == 1000 q ~= 1000 q != 1000 true & true true & false false & false false & false & false false * false true | true true | false false | false ~false ~true xor(false, false) xor(false, true) xor(true, true) xor(true, false, true) doc xor ~xor(true, false) true == false q 500 <= q <= 1500 w = 2000 500 <= w <= 1500 500 <= w (500 <= q) & (q <= 1500) (500 <= w) & (w <= 1500) (500 >= w) & (w >= 1500) false (500 >= w) | (w >= 1500) [1 2 3] > [2 3 1] [1 2 3] > 2 [1 2 3] > [2 3] [1 2 3] > [2 3 1] [1 2 3] > [2 3 1]' [1 2 3] > [2 3]' [1 2 3] > 2 & [1 2 3] > 3 [1 2 3] >= 2 & [1 2 3] >= 3 [1 2 3] >= 2 [1 2 3] >= 3 [1 2 3] > 2 & [1 2 3] == 3 [1 2 3] > 2 | == 3 v = [1 2 3] w = [1 0 3] v == w all(v == w) any(v == w) all([true false false true]]) all([true false false true]) %%%% x = randi([0 9], 1, 10) findstr(x, [4 9]) x(11:13) = [4 9 3] x clc x findstr(x, [4 9]) all([true true true true]) all([true true true false]) all([true true; true false]) any([false false false false]) any([false true false false]) any([false true false true]) Z = zeros(3, 5) Z == 0 all(Z == 0) all(all(Z == 0)) all(Z(1:end) == 0) Z Z2 = Z Z2(2,2)=0.0001 all(all(Z == 0)) all(all(Z2 == 0)) v w isequal(v, w) isequal(zeros(3,5), Z) Z isequal(zeros(3,5), Z2) v w v == w all(v == w) isequal(v, w) zeros(3,5) == 0 all(zeros(3,5) == 0) all(all(zeros(3,5) == 0)) isequal(zeros(3,5), 0) v w u = [1 2 3 4] all(v == u) isequal(v, u) s1 = 'Eu quero um paozinho' s2 = 'ovo' s1 == s2 s3 = 'eva' s2 == s3 strcmp(s1, s2) strcmp(s2, s3) strcmp(s2, s2) s4 = 'OVO' s4 = 'Eva' s3 s4 strcmp(s3, s4) strcmpi(s3, s4) strcmpi(s2, s4) s1 findstr(s1, 'paozinho') findstr(s1, 'ovo') strcmp(r, fliplr(r)) r = 'anotaramadatadamaratona' strcmp(r, fliplr(r)) r = 'Anotaram a data da maratona?' strcmp(r, fliplr(r)) r('a':'z') ('a':'z' ('a':'z') r == ' ' r ~= ' ' r(r ~= ' ') r(r < 'a' & r > 'z') r('a' <= r & r <= 'z') r = lower(r) r('a' <= r & r <= 'z') clc r('a' <= r & r <= 'z') r lower('Ola') upper('Ola') 'a':'z' 'a':2:'z' 'b':2:'z' r('a' <= r & r <= 'z') 'a':pi:'z' DOC deblank doc deblank r deblank(r) r('a' <= r & r <= 'z') r clc r r('a' <= r & r <= 'z') r('a' == r & r == 'e' & 'i' == r & 'u' == r & r == 'o') r(r == 'a' | r == 'e' | 'i' == r | 'u' == r | r == 'o') r r(r == 'a' | r == 'e' | 'i' == r | 'u' == r | r == 'o' | r == ' ') 'a' : 'z' 'a' < 'b' A < 'b' 'A' < 'b' 'a' < 'B' r r(r == 'a' | r == 'e' | 'i' == r | 'u' == r | r == 'o' | r == ' ') doc erase erase lookfor erase r r('a' <= r & r <= 'z') 'a' <= r 'a' <= r & r <= 'z' r('a' <= r & r <= 'z') r(1) = 'A' r('a' <= r & r <= 'z') r('A' <= r & r <= 'z') r(('a' <= r & r <= 'z') | ('A' <= r & r <= 'Z')) r('a' <= r & r <= 'z' | 'A' <= r & r <= 'Z') r(2) = '[' r('a' <= r & r <= 'z' | 'A' <= r & r <= 'Z') r('a' <= r & (r <= 'z' | 'A' <= r) & r <= 'Z') r('a' <= r) r(3) = '{' r('a' <= r) r = 'Anotaram a data da maratona?' r('a' <= r & r <= 'z') r('a' <= lower(r) & lower(r) <= 'z') % Find r doc find find(r == 'd') find(r == 'da') find([false false true false true]) r == 'da' s = 'casa' find(s == 'cama') s == 'cama' find([false false true false true]) % Define initial conditions. y0 = [20; 20]; % Simulate the differential equation. [t,y] = ode45(@lotka, 0:0.005:15, y0); % Animate. multicomet(t, y) </syntaxhighlight>