フィルターのクリア

how to plot different graphs for each iteration of a for loop?

4 ビュー (過去 30 日間)
Nabhdeep Bansal
Nabhdeep Bansal 2014 年 8 月 24 日
コメント済み: the cyclist 2014 年 8 月 24 日
t=linspace(0,12,1000);
T=2;
Y=g(t)';
f=0;
N=50;
hold on;
h=zeros(N,1);
clr=lines(N);
for n=1:25:N;
line(t,Y,'linewidth',5)
grid on;hold on;
A=(1/T)*quadgk(@g,0,T);
P=@(t)g(t).*(cos(n*pi*t));
Q=@(t)g(t).*(sin(n*pi*t));
Ax=(2/T)*quadgk(P,0,T);
Bx=(2/T)*quadgk(Q,0,T);
f=f+(Ax*cos(pi*n*t)+Bx*sin(pi*n*t));
final=A+f;
h(n)=plot(t,final,'linewidth',2,'Color',clr(n,:));
end
hold off;
legend(h, num2str((1:N)','harmonic-%d')).
I wish to plot different graphs for every iteration done. Is it poosible?

採用された回答

the cyclist
the cyclist 2014 年 8 月 24 日
編集済み: the cyclist 2014 年 8 月 24 日
Put the "figure" command at the start of the for loop.
doc figure
for details.
Also, in the line
A=(1/T)*quadgk(@g,0,T);
you don't want the "@". It should be just
A=(1/T)*quadgk(g,0,T);
  2 件のコメント
Nabhdeep Bansal
Nabhdeep Bansal 2014 年 8 月 24 日
thanks Sir. Though I have already applied what you said but still I wish to know what is the difference between g & @g here.
the cyclist
the cyclist 2014 年 8 月 24 日
It's easy to get confused on this. What quadgk() requires as its first argument is a function handle. So, for example, if you wanted to integrate the sine function, you would use
@sin
because that is the handle to the sine function. However, you have defined g yourself, and g is itself a function handle.
See this documentation page for details.

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by