フィルターのクリア

How to keep count in a nested for loop?

14 ビュー (過去 30 日間)
john
john 2015 年 11 月 17 日
編集済み: baby 2021 年 9 月 26 日
Hi, I'm sure the answer is simple but I just can't figure it out. Let's say I have this code:
for i=1:3
for j=1:3
count=??;
end
end
count
I want the result to be count=[1 2 3 4 5 6 7 8 9]
Thanks

回答 (2 件)

the cyclist
the cyclist 2015 年 11 月 17 日
There are many ways to do this. Here is one.
c = 0;
for i=1:3
for j=1:3
c=c+1;
end
end
count = 1:c
  1 件のコメント
baby
baby 2021 年 9 月 26 日
編集済み: baby 2021 年 9 月 26 日
you saved my life.

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


the cyclist
the cyclist 2015 年 11 月 17 日
Here is one way:
irange = 1:3;
jrange = 1:3;
for i=irange
for j=jrange
end
end
count = 1:(numel(irange)*numel(jrange));

カテゴリ

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