Mudanças entre as edições de "FIC MATLAB 2018-1/Aula-5"
Ir para navegação
Ir para pesquisar
(Criou página com '<syntaxhighlight lang=matlab class="mw-collapsible"> % Indexação de vetores e matrizes % Por índice doc randi v1 = randi(100,1,10) v1(1) v1(3) format compact v1(7) v2 = randi(100,10,1) v2(1)...') |
|||
(Uma revisão intermediária pelo mesmo usuário não está sendo mostrada) | |||
Linha 124: | Linha 124: | ||
A3(2:4,5:end) = [] | A3(2:4,5:end) = [] | ||
A3(2:4,:) = [] | A3(2:4,:) = [] | ||
+ | |||
+ | % Concatenação de matrizes e vetores | ||
+ | v = [1 2 30] | ||
+ | u = [-1 0 40 9] | ||
+ | [v u] | ||
+ | [v, u] | ||
+ | w = [1; 5; 7]' | ||
+ | w = [1; 5; 7] | ||
+ | p = [10; 20; 30] | ||
+ | [w; p] | ||
+ | [1 2 ones(1, 7) 8] | ||
+ | p | ||
+ | [p; p; p] | ||
+ | [p p] | ||
+ | A = randi(100, 2, 5) | ||
+ | B = randi([100 200], 3, 2) | ||
+ | C = randi([-100 =1) | ||
+ | C = randi([-100 -1], 3, 3) | ||
+ | clc | ||
+ | A | ||
+ | B | ||
+ | C | ||
+ | D = [A; B C] | ||
+ | A4 | ||
+ | [A4(:, 1:5) A4(:, 7:end)] | ||
+ | A4 | ||
+ | A4 = [A4(:, 1:5) A4(:, 7:end)] | ||
+ | |||
+ | % Repmat | ||
+ | G = randi(100, 2, 3) | ||
+ | T = repmat(G, 3, 2) | ||
+ | [G G; G G; G G] | ||
+ | T = repmat(G, 3, 1) | ||
+ | G | ||
+ | G(1) | ||
+ | G(:) | ||
+ | |||
+ | % Reshape | ||
+ | reshape(G, 6, 1) | ||
+ | reshape(G, 5, 2) | ||
+ | reshape(G, 5, 1) | ||
+ | size(G) | ||
+ | G | ||
+ | reshape(G, 3, 2) | ||
+ | G' | ||
+ | reshape(G, 6, 1) | ||
+ | reshape(G, 1, 6) | ||
+ | reshape(G, 12, 0.5) | ||
+ | 1:20 | ||
+ | reshape(1:20, 5, 4)' | ||
+ | reshape(1:20, 4, 5) | ||
+ | reshape(1:20, 5, 4)' | ||
+ | JJ = reshape(1:20, 5, 4)' | ||
+ | reshape(JJ, 2, 10) | ||
+ | reshape(JJ, 10, 2)' | ||
+ | JJ | ||
+ | reshape(JJ', 2, 10) | ||
+ | reshape(JJ', 10, 2)' | ||
</syntaxhighlight> | </syntaxhighlight> |
Edição atual tal como às 22h01min de 27 de março de 2018
% Indexação de vetores e matrizes
% Por índice
doc randi
v1 = randi(100,1,10)
v1(1)
v1(3)
format compact
v1(7)
v2 = randi(100,10,1)
v2(1)
v2(4)
v2(9)
v2(11)
% Por subscrito
A1 = randi(10,3,4)
A1(1,2)
A1(1)
A1(2)
A1(3)
A1(4)
v1
v1(1,7)
v1(7)
v1(2,7)
v1(7,1)
% Submatrizes
v1
v1([1 3 6])
v1([1; 3; 6])
v1([1 3; 6 8])
A2 = v1([1 3; 6 8])
A2(:)
A2'(:)'
A2 = v1([1 3; 6 8])
A1
A1(2,[1 3 4])
A1(2,[1 2 3 4])
A1(2,1:4)
A1(2,:)
A1(:,4)
A1(:,:)
A1(:)
% Palavra chave "end"
A3 = randi(100,8,8)
A3(:,[1 3 5 7])
A3(:,1:2:8)
A3(:,1:2:)
A3(:,1:2::)
size(A3)
size(A1)
A1
size(A1,1)
size(A1,2)
A3(:,1:2:size(A3))
1:2:size(A3)
1:2:[5 6]
1:2:[5 8]
1:2:[8 5]
[1 3]:[2 1.5]:[8 5]
A3(:,1:2:size(A3,2))
A3(:,1:2:end)
v1
v1(end)
v1(end-1)
v1(end:1)
10:1
10:-1:1
v1(end:-1:1)
v1
sort(v1)
[a,i] = sort(v1)
A3
A3(:,1:2:end)
A3(:,2:2:end)
A3(:,0:2:end)
A3
A3(:,[1 2 4 4 4 4 5])
A3(:,[1 2 4*ones(1,3) 5])
ones(1,3)
4*ones(1,3)
A3
% Linhas: 3 a 6; Colunas: 2 a 6
A3(3:6,2:6)
A3([3 6],[2 6])
A3([3 6]:[2 6])
3:2
% Indexação do lado esquerdo da atribuição
A3(3:6,2:6)
ans = A3(3:6,2:6)
A3
A3(5,3)
A3(5,3) = -5
A3(5,[1 5]) = -5
A3(2,1:2:end) = 0
A3(1:4,1:2:end) = 0
A4 = zeros(8,8)
A4(3:6,3:6) = 1
A4(3:6,3:6) = randi(100,4,4)
A4(3:5,3:6) = randi(100,4,4)
A4
A1
A1(5,:) = 17
A1(10,:) = 99
A3
A3(:,6) = []
A3
A3 = [0 44 0 96 0 82 0 39
0 39 0 35 0 25 0 57
0 77 0 59 0 93 0 8
0 80 0 23 0 35 0 6
-5 19 -5 76 -5 20 92 54
32 49 17 26 26 26 29 78
96 45 12 51 85 62 76 94
4 65 50 70 26 48 76 13]
A3(:,1 2 3 4 5 7 8)
A3(:,[1 2 3 4 5 7 8])
A3
A3(2:4,5:end) = []
A3(2:4,:) = []
% Concatenação de matrizes e vetores
v = [1 2 30]
u = [-1 0 40 9]
[v u]
[v, u]
w = [1; 5; 7]'
w = [1; 5; 7]
p = [10; 20; 30]
[w; p]
[1 2 ones(1, 7) 8]
p
[p; p; p]
[p p]
A = randi(100, 2, 5)
B = randi([100 200], 3, 2)
C = randi([-100 =1)
C = randi([-100 -1], 3, 3)
clc
A
B
C
D = [A; B C]
A4
[A4(:, 1:5) A4(:, 7:end)]
A4
A4 = [A4(:, 1:5) A4(:, 7:end)]
% Repmat
G = randi(100, 2, 3)
T = repmat(G, 3, 2)
[G G; G G; G G]
T = repmat(G, 3, 1)
G
G(1)
G(:)
% Reshape
reshape(G, 6, 1)
reshape(G, 5, 2)
reshape(G, 5, 1)
size(G)
G
reshape(G, 3, 2)
G'
reshape(G, 6, 1)
reshape(G, 1, 6)
reshape(G, 12, 0.5)
1:20
reshape(1:20, 5, 4)'
reshape(1:20, 4, 5)
reshape(1:20, 5, 4)'
JJ = reshape(1:20, 5, 4)'
reshape(JJ, 2, 10)
reshape(JJ, 10, 2)'
JJ
reshape(JJ', 2, 10)
reshape(JJ', 10, 2)'