Subtract rows in matrix using loop

2 views (last 30 days)
Hi, I have a 11 x 3541 matrix. For each column I want subtract; row1 from row1 then,row1 from row 2 then, row2 from row 3 and so on. I have tried using a loop but it doesn't work.
for i= 0:12
mono_am = UVI_all_am(1+i,:) - UVI_all_am(i+1-i,:);
end

Accepted Answer

Stephen23
Stephen23 on 11 May 2017
Edited: Stephen23 on 11 May 2017
Use diff:
diff(UVI_all_am,1,1)
And stick a row of zeros along the top if you really need row1 - row1.
  3 Comments
Stephen23
Stephen23 on 11 May 2017
X = diff(UVI_all_am,1,1);
X = [zeros(1,size(X,2));X];

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!