for loop does not plot all the plots

1 回表示 (過去 30 日間)
tomer polsky
tomer polsky 2022 年 3 月 9 日
コメント済み: tomer polsky 2022 年 3 月 9 日
I am trying to plot this code :
clc;clear all;close all;
n=3;
t=linspace(0,24*n,100e3*n);
y1=cos(t*(pi/3))+sin(t*(pi/4));
plot(t,y1);
hold on;
plot(24*1,y1(1*100e3),'*');
hold on;
plot(24*2,y1(2*100e3),'*');
hold on;
plot(24*3,y1(3*100e3),'*');
using for loop but for some reason I get only the last plot .
this is my code using for loop:
clc;clear all;close all;
n=3;
t=linspace(0,24*n,100e3*n);
y1=cos(t*(pi/3))+sin(t*(pi/4));
plot(t,y1)
hold on;
for i=1:n
hold on;
plot(24*n,y1(n*100e3),'*');
hold on
end
hold off
where is my problem ?

回答 (1 件)

Torsten
Torsten 2022 年 3 月 9 日
plot(24*i,y1(i*100e3),'*');
instead of
plot(24*n,y1(n*100e3),'*');
  1 件のコメント
tomer polsky
tomer polsky 2022 年 3 月 9 日
can't belive I did not notice it ... thank you very much !!!

サインインしてコメントする。

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by