MATLAB Answers

Replacing elements in matrix columns

6 views (last 30 days)
Fayyaz
Fayyaz on 14 Apr 2015
Answered: Chris McComb on 14 Apr 2015
Hi,
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.

  0 Comments

Sign in to comment.

Answers (1)

Chris McComb
Chris McComb on 14 Apr 2015
You can do the replacement using logical indexing. The replacement for 34 --> 1 would be as follows:
for i=2:3
idx = (mat(:,i) == 34);
mat(idx,i) = 1;
end

  0 Comments

Sign in to comment.