Convert loop to vectorization
이전 댓글 표시
Here is simple code where I would like to remove for loop. A=[9;9;9]; c1=[2;3;5] for i=1:length(c1) c=c1(i,1); [B]=Subsum (A,c) i=i+1; end
Function subsum is defined as below
function [B] = Subsum (A,c) B=A-c; end
Desired output First loop B=[ 7 ;7;7] second loop B=[6;6;6] and Third loop B=[4;4;4]
채택된 답변
추가 답변 (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!