Plotting values from while loop results

5 ビュー (過去 30 日間)
UOE
UOE 2012 年 11 月 27 日
Hi, anyone knows how do i store the values for b in vector form, so that i can plot a graph using the values of b.
a=0
while a<100
b= 2*a
a= a+1
end

回答 (2 件)

Matt Fig
Matt Fig 2012 年 11 月 27 日
編集済み: Matt Fig 2012 年 11 月 27 日
a = 1;
while a<=100
b(a) = 2*a;
a = a+1;
end
plot(b)
In general, the more MATLABish way to get b is like this:
b2 = 2*(0:100);
Now b2 is equal to b.

Image Analyst
Image Analyst 2012 年 11 月 27 日
a=0
while a<100
b(a+1) = 2*a;
a = a+1;
end
plot(b);
or even better (to get the "a" axis correct so you'll have b=0 at a=0 instead of at 1):
a = 0 : 99;
b = 2 * a;
plot(a, b, 'ro-');
grid on;

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by