Results of a while loop wont store in array

4 ビュー (過去 30 日間)
Sam Thorpe
Sam Thorpe 2019 年 3 月 5 日
コメント済み: Sam Thorpe 2019 年 3 月 6 日
I have the following script which calculates the quadratics of an equation in a function.
x=[10:100];
a=10;
b=100;
c=0;
resultsvector=[];
while a<b;
a=a+1;
y=quad(@myfun,c,a)
resultsvector=[resultsvector; y];
end
I have managed to get it to calculate the value of y in the range of 10:100 but now I cannot get it to store the values in array so I can plot them against the range of x. What am I missing?
Thanks

採用された回答

Bob Thompson
Bob Thompson 2019 年 3 月 5 日
You need to index your result within the loop.
x=[10:100];
a=10;
b=100;
c=0;
resultsvector=[];
count = 0; %%%%%%%%%%%%%%
while a<b;
count = count + 1; %%%%%%%%%%%%%
a=a+1;
y(count)=quad(@myfun,c,a); %%%%%%%%%%%%%
resultsvector=[resultsvector; y];
end
I did not index your independent variable, but I figure this should get you started.
  1 件のコメント
Sam Thorpe
Sam Thorpe 2019 年 3 月 6 日
Thanks very much for the help. I have got it working.

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

その他の回答 (0 件)

カテゴリ

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