Reputation: 179
My 1x500 matrix consist of numbers, I want to sum all the numbers between two indices, lets say between 100 and 300. Forgot how to do that, help would be appreciated.
Upvotes: 1
Views: 189
Reputation: 8238
Let's say we have the matrix:
m = [1,2,3,4,5,6,7,8];
and indices:
idx1 = 3;
idx2 = 6;
Getting the sum is easy:
sum(m(idx1:idx2))
So the answer to your question is:
ans = sum(your_m1x500(100:300));
Upvotes: 2