フィルターのクリア

Pass one value at a time from a matrix to a for loop

1 回表示 (過去 30 日間)
Damith
Damith 2014 年 10 月 29 日
コメント済み: Stephen23 2014 年 10 月 30 日
Hi,
I need to pass one value at a time from matrix to iprev inside the for loop. For example, first value of iprev is 11 then 19 and so on. How can I modify my code to do that?
matrix=[11 19 21 29 37 31 45 47 48 54 60 57 66 67 69 86 84 89 111 113 117 120 122 128 139 143 152 161 161 165 170 170];
isemp = all(isnan(ave),1);
for ii = find(isemp)
ave(:,ii) = ave(:,iprev);
end
Any help is appreciated.
Thanks in advance.
  1 件のコメント
Stephen23
Stephen23 2014 年 10 月 30 日
What is the reason for passing the values "one at a time" from one array to another one? Why not just use indexing to transfer all required values in one go?

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

採用された回答

James Tursa
James Tursa 2014 年 10 月 29 日
E.g., (caution: code not protected against iprev too large for matrix size)
iprev = 1;
for ii = find(isemp)
ave(:,ii) = ave(:,matrix(iprev));
iprev = iprev + 1;
end
  1 件のコメント
Damith
Damith 2014 年 10 月 29 日
Thanks. it worked.

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

その他の回答 (0 件)

カテゴリ

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