Replacing elements in matrix columns
9 views (last 30 days)
Show older comments
Fayyaz on 14 Apr 2015
Answered: Chris McComb on 14 Apr 2015
I have a matrix 61312*3, and I want to replace the element of the 2nd and 3rd column by some numbers. For example, in 2nd and 3rd column, I need to replace
34 by 1
10, 17, 22, 39, and 59 by 2
and so on.
How should I proceed? Thanks in advance.
Chris McComb on 14 Apr 2015
You can do the replacement using logical indexing. The replacement for 34 --> 1 would be as follows:
idx = (mat(:,i) == 34);
mat(idx,i) = 1;
Find more on Matrices and Arrays 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!