Appending to an array/vector

5 ビュー (過去 30 日間)
Emma
Emma 2020 年 1 月 21 日
回答済み: James Tursa 2020 年 1 月 21 日
I have a while loop that is running. Inside the while loop, I want to create a vector of values. The loop is iterating several times, and during each iteration should be calculating the max error for my problem. I would like a vector that contains all of the max errors. For example, if there were three iterations, 1, 2 and 3, and the max errors were .1, .2, and .5 respectively, the vector at the end should be [.1 .2 .5]. However, when I code this, it results in just a one digit number corresponding to the max error of the last iteration.

回答 (1 件)

James Tursa
James Tursa 2020 年 1 月 21 日
We would need to see your code to give a more specific answer, but the general outline is to index into your result vector. E.g.,
maxerror = zeros(n,1);
for k=1:n
maxerror(k) = the max error for this iteration
end

カテゴリ

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