how to add different values to some particular rows and columns?
3 views (last 30 days)
Show older comments
Hello..
a = [0 10 20 30 40;6 10 20 30 40;12 10 20 30 40;18 10 20 30 40;24 10 20 30 40];
and if i want to add 1 to row no. 1, add 2 to row no. 2, add 3 to row no.3 and so on....but excluding column no. 1 i.e i don't want to add any value in column no.
The output which i am expecting is :
b = [0 10 20 30 40;6 11 21 31 41;12 12 22 32 42;18 13 23 33 43;24 14 24 34 44]
0 Comments
Accepted Answer
madhan ravi
on 10 Mar 2019
Since 2016b:
b=a;
b(2:end,2:end)=b(2:end,2:end)+(1:size(b,1)-1).'
Prior to 2016b:
b=a;
b(2:end,2:end)=bsxfun(@plus,b(2:end,2:end),(1:size(b,1)-1).' )
3 Comments
More Answers (0)
See Also
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!