Replacing elements in matrix columns

2 visualizzazioni (ultimi 30 giorni)
Fayyaz
Fayyaz il 14 Apr 2015
Risposto: Chris McComb il 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.

Risposte (1)

Chris McComb
Chris McComb il 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

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by