Effacer les filtres
Effacer les filtres

convert a logical matrix to the numeric one

3 vues (au cours des 30 derniers jours)
som
som le 11 Avr 2012
Hi all; How can I convert a "logical matrix' to the numeric one. For example B matrix is below . I want to convert it to the B2 matrix . How can I do this without using any for loops?
B= [true true true true; false true true true; false false true true];
B2=[10 10 10 10; 5 10 10 10; 5 5 10 10]
Any help would be appropriated.

Réponses (1)

Andrei Bobrov
Andrei Bobrov le 11 Avr 2012
in your case
B2 = B*5 + 5
OR
k = [5 10]
B2 = k(B + 1)
  1 commentaire
Jan
Jan le 11 Avr 2012
Or:
B2 = repmat(5, size(B));
B2(B) = 10;

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by