Avoid for loop on sum on given indexes, use accumarray?
이전 댓글 표시
Hi,
I'm trying to get rid of the for loop on the follwoing code:
S=zeros(100,50);
V=rand(1,50);
Index=round(50*rand(1,50))
for i=1:50
S(:,Index(i))=S(:,Index(i))+V(i);
end
I probably need to use accumarray but I cannot figure how.
Thanks a lot
댓글 수: 2
Walter Roberson
2019년 7월 10일
Why are you creating 100 rows when you do the same thing to all of them? Why not create one row with the values and later replicate to 100 copies?
Lenaic Couedel
2019년 7월 10일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!