How to replace two nested for with vectorization
古いコメントを表示
How can I write this without loops
[nrows, ncols] = size(A);
for i = 1:nrows
for j = 1:ncols
if A(i,j)~=0
AC(i) = AC(i)+C(i,A(i,j));
else
break
end
end
end
3 件のコメント
KSSV
2016 年 3 月 29 日
Are you sure that AC in the above is an array?
etudiant_is
2016 年 3 月 29 日
KSSV
2016 年 3 月 29 日
It's dimension is equal to i.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Language Fundamentals についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!