How to plot matrix inside for loop ?

3 ビュー (過去 30 日間)
Waranga Ratnayake
Waranga Ratnayake 2019 年 3 月 20 日
回答済み: Andrei Bobrov 2019 年 3 月 20 日
clc
close all
A=[0 3/10;3/5 0];
u=[0.3 ;0.8];
p=[0;0];
for n=1:50
p=A*p + u;
plot (n,p(1),'-');hold on
plot (n,p(2),'-');hold on
end
So there are values coming to the p(1) and p(2) in p , so it starts from 1 to 50 and i want to put those p(1) and p(2) in to a plot and it has to be drawn using a line . so my code doesn't draw lines but it draws dots .

採用された回答

Akira Agata
Akira Agata 2019 年 3 月 20 日
Like this?
A = [0 3/10;3/5 0];
u = [0.3 ;0.8];
p = nan(2,51);
% Inisital condition
p(:,1) = [0;0];
for n=1:50
p(:,n+1) = A*p(:,n) + u;
end
% Plot the result
figure
plot(0:50,p(1,:))
hold on
plot(0:50,p(2,:))
plot.png

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2019 年 3 月 20 日
A = [0 3/10;3/5 0];
u = [0.3 ;0.8];
p = [0;0];
P = zeros(2,50);
for n = 1:50
p = A*p + u;
P(:,n) = p;
end
plot (P.');

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by