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!