FIC MATLAB 2017-2/Aula-4

De MediaWiki do Campus São José
Ir para navegação Ir para pesquisar
%-- 19-09-2017 19:09:37 --%
format compact
% Outros comandos de plotagem
x = 0:0.01:1
edit
y = x.^2 + 1
plot(x, y)
z = cos(2*pi*x);
plot(x, z)
plot(x, y)
figure
plot(x, z)x
plot(x, z)
plot(x, z, 'r')
figure(1)
plot(x, y, 'm')
figure(4)
close all
figure
subplot(2, 3, 1)
plot(x, y)
subplot(2, 3, 5)
plot(x, z)
hold on
plot(x, -z, 'r')
title('meus cossenos')
subplot(2, 3, 2:3)
stem(x, x.^3)
subplot(2, 2, 3)
figure
close all
% Números aleatórios
randi([3 7], 3, 10)
randi([0 1], 1, 20)
randi(3, 1, 20)
doc randi
rand(3, 9)
rand()
rand
rand()
rand(4)
R = rand(100);
max(max(R))
format long
max(max(R))
min(min(R))
rand(1, 10) + 1
format short
rand(1, 10) + 1
rand(1, 10) + 4
rand(1, 10) * 4
rand(10) * 4
3 + rand(10) * 7
(10/7) * (rand(10) * 7)
(10/7) * (rand(10) + 7)
7 + rand(10)*3
randn(4, 2)
randn(20)
randn(10)
randn(10) * sqrt(5)
randn(10) * sqrt(5) + 17
X = randi(1, 16)
X = rand(1, 16)
X = randi([0 3], 1, 10)
bins = 0:3
freq = hist(X, bins)
bar(bins, freq)
stem(bins, freq)
plot(bins, freq)
hist(X)
X = randi([0 3], 1, 1000);
hist(X)
X = randi([0 3], 1, 100000);
hist(X)
X = rand(1, 10000)*3 + 7;
hist(X)
hist(X, 50)
doc hist
hist(X, 6.5 : 0.2 : 11)
X = randn(1, 10000);
hist(X)
hist(X, 30)
figure
Y = randn(1, 10000) * sqrt(5) + 17;
hist(Y, 30)
% Indexação de vetores e matrizes - Show do Diego
% Indexação de um elemento
clear all
v = randi(10,1,10)
v(1)
v(2)
v(7)
w = randi(10,10,1)
w(1)
w(2)
v
v(1:5)
v(1:2:5)
v(1.5)
v(0)
v(-1)
v(-5)
length(v)
v(40)
v
v(1:10)
v(:)
v(5:length(v))
v(5:end)
v
v(5:end-1)
v
v(end:-1:1)
v
v([1 4 5 9])
v([1 4 4 5 9])
A = randn(5,5)
A(1)
A(2)
A(3)
A
A(4)
A(5)
A(6)
A
A(11:15)
A(2,3)
A(1:5,3)
A(:)
:
% Índice
A(8)
% Subscript
A(3,2)
A
A(:,2)
A
A(4,:)
A
% Linha: 3; Coluna: 4 a 5
A(3,4:5)
A(3,[4 5])
A(3,(end-1):end)
A
A(3:4,[4 5])
A
A(1:2:end,1:2:end)
A(1:2:end,[1 3 5])
A(1:2:end,[3 3 3])
A(1:2:end,[5 3 1])
A([1 3 5; 1 3 5])
A
A([1 3 5; 1 3 9])
A([1 3 5; 1 3 5],[1 3 5; 1 3 5])
A
% Lado esquerdo vs lado direito
A(3,2)
A(3,2) = 10
B = A(3,2)
A
A(:,2) = 10
A(:,2) = 10:10:50
A(:,2) = 10:10:60
A(:,2)
10:10:60
A
A(3:5,3:5) = eye(3)
A(end:-1:1,end:-1:1)
B = A(end:-1:1,:)
A
B
C = B(:,end:-1:1)
% Removendo linhas ou colunas
A
A([1 2 4 5],:)
A(3,:) = []
[]
size([])