フィルターのクリア

Want to run the code for n values of X0, tried using for loop but didn,t get desired output.how to run for n values of X0?

2 ビュー (過去 30 日間)
if true
X = [ 0, 15 30 45 ];
Y = [50, 8.5, 2, 0.5];
X0 = 0;
n = 100;
f = 0.1;
x = linspace(min(X),max(X),n);
y = interp1(X,Y,x,'spline');
xt = X0+(0.1*(max(X)-min(X))*[-1 0 1]);
m = diff(y)./diff(x);
m = [m, m(end)];
k = min([find(x >= X0,1,'first'), length(x)]);
yt = y(k) + m(k)*(0.1*(max(X)-min(X))*[-1 0 1]);
plot(X,Y,'ro', x,y,'-b',xt,yt,'--g');
% code
end
  3 件のコメント
Geoff Hayes
Geoff Hayes 2014 年 6 月 11 日
What do you want the n values for X0 to be? The first is zero, the second one is… What should this sequence be?
vaishali
vaishali 2014 年 6 月 11 日
編集済み: vaishali 2014 年 6 月 11 日
X0=0:10

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

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 6 月 11 日
If X0 varies from 0 to 10 (and we assume a step size of 1), then a for loop could be introduced as follows
X0data = 0:1:10;
for i=1:length(X0data)
X0 = X0data(i);
X = [ 0, 15 30 45 ];
Y = [50, 8.5, 2, 0.5];
% etc.
plot(X,Y,'ro', x,y,'-b',xt,yt,'--g');
hold on; % to allow multiple plots on same figure
end
Try the above and see what happens.
  4 件のコメント
vaishali
vaishali 2014 年 6 月 11 日
want to plot outside for loop;want to keep command: plot(X,Y,'ro', x,y,'-b',xt,yt,'--g'); hold on; outside for loop .is it possible?
Geoff Hayes
Geoff Hayes 2014 年 6 月 11 日
Yes…but then you have to "save" X and Y at each iteration. Try it out and see.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSequence and Numeric Feature Data Workflows についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by