How to replace two nested for with vectorization
Ältere Kommentare anzeigen
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 Kommentare
KSSV
am 29 Mär. 2016
Are you sure that AC in the above is an array?
etudiant_is
am 29 Mär. 2016
KSSV
am 29 Mär. 2016
It's dimension is equal to i.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!