Subtract each column of matrix until -3 is finished
Show older comments
For example, i have a matrix a = [0 1 2 3 4]. How do I subtract each column by 1?
a = [0 3 2 6 4]
b = [0 2 1 2 3]
remainder = size(a, 2) - sum(b)
The remainder is -3. I need to minus from b when b(i) ~= 0 so that at the end the b = [0 1 0 1 3].
Thank you.
Accepted Answer
More Answers (1)
Walter Roberson
on 14 Dec 2011
Does the minus sign of -3 indicate the third from the start or the third from the end? Your example is ambiguous about that.
Third from the start:
a(1:abs(b)) = a(1:abs(b)) - 1;
Third from the end:
a(1:end-abs(b)+1) = a(1:end-abs(b)+1) - 1;
2 Comments
Fangjun Jiang
on 14 Dec 2011
The result are all wrong though!
Walter Roberson
on 14 Dec 2011
ind = find(a);
ind = ind(1:abs(b));
a(ind) = a(ind) - 1;
Categories
Find more on Spline Postprocessing 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!