Convert loop to vectorization
Show older comments
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]
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!