フィルターのクリア

Placing the ouputs of while loop in an array

2 ビュー (過去 30 日間)
Joe
Joe 2012 年 11 月 19 日
I don't necessarily have a code written, yet but I was just wondering how I could take the outputs(all iterations) of a while loop and return a vector with the outputs.
Thanks.

回答 (1 件)

Harshit
Harshit 2012 年 11 月 19 日
What is the problem. Start putting them as soon as they are generated.
if true
index = 0
a(index)=output
index = index+1
end
  2 件のコメント
Joe
Joe 2012 年 11 月 19 日
編集済み: Joe 2012 年 11 月 19 日
I'm sorry I'm still having trouble understanding how to go about doing this. My code is as follows:
if true
function [r,rHist,N,fRoot] = newtonRaphE7(fHan,dfHan,x0,fTol,iterMax)
counter = 0;
while abs(fHan(x0)) > fTol
x0 = x0 - (fHan(x0))/(dfHan(x0))
counter = counter + 1
if counter > iterMax
error(['Number of iterations exceeded the limit'])
end
end
N = counter
r = x0
end
So I would like to add the output rHist, and have it be a vector comprised of the output for all iterations of the while loop.
Jan
Jan 2012 年 11 月 19 日
編集済み: Jan 2012 年 11 月 19 日
@Harshit: Move the "index = 0" out of the loop.
@Joe: You define a nested function, but do not show from where it is called.

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

カテゴリ

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