Replacing elements in matrix columns
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
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
0 Commenti
Vedere anche
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!