While loop inside for loop

2 ビュー (過去 30 日間)
Matt Kitchen
Matt Kitchen 2019 年 4 月 26 日
回答済み: Star Strider 2019 年 4 月 26 日
I'm trying to figure out why my random dice excersise is not working. The while loop works, but when I add a for loop in an attempt to save the number of iterations, it overwrites the rest of the vector. Any help would be useful.
Capture.PNG
Capture1.PNG

回答 (1 件)

Star Strider
Star Strider 2019 年 4 月 26 日
You posted an image of your code rather than the code itself, so I can’t copy it and run it.
One option would be to add these lines just before the end of your for loop:
xvs{n} = xv;
yvs{n} = yv;
That would save them in the respective cell arrays so you would have them to process later.
Also, you don’t need the:
n = n + 1;
assignment. The for loop will iterate that itself, and ignore anything you do to change it in the loop.

カテゴリ

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