Effacer les filtres
Effacer les filtres

Replacing elements in matrix columns

2 vues (au cours des 30 derniers jours)
Fayyaz
Fayyaz le 14 Avr 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.

Réponses (1)

Chris McComb
Chris McComb le 14 Avr 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

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by