Extract row each iteration

I would like to extract a 1-row vector "K" that changes each iteration and create a matrix "C" with rows equal to the vector. I have a while loop that determines the values of "K" and just want to rerun the program 1000 times and save all "K" in the Matrix "C" as rows. This is what I am doing but looks like something is not as it is supposed be:
for ii=1:1000
while ....
K=...
end
C(ii,:)=K
end

5 件のコメント

Stephen23
Stephen23 2018 年 2 月 22 日
編集済み: Stephen23 2018 年 2 月 22 日
"...but looks like something is not as it is supposed be"
Do you have any problem with the loops? Are the output data what you would expect to get?
Miroslav Mitev
Miroslav Mitev 2018 年 2 月 22 日
It does not give me output for "C" at all. It says there is no such variable as "ii". I have just defined "ii" and created a while loop where "ii=ii+1" in every loop and it works fine now. But is it possible to be done with for loop?
Stephen23
Stephen23 2018 年 2 月 22 日
@Miroslav Mitev: please make a new comment and upload your code by clicking the paperclip button.
Raphael Klapczynski
Raphael Klapczynski 2018 年 2 月 22 日
編集済み: Raphael Klapczynski 2018 年 2 月 22 日
It looks like a problem caused by K vector. The for loop works without any problems for me. Or you manipulate ii inside the while-loop.
for ii=1:4
K = rand([1 3]);
C(ii,:)=K
end
Miroslav Mitev
Miroslav Mitev 2018 年 2 月 22 日
Thank you for your comments. I did solve the issue.

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2018 年 2 月 22 日

コメント済み:

2018 年 2 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by