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!