Convert numerical Matrix values into logical Matrix

6 vues (au cours des 30 derniers jours)
ray d
ray d le 17 Déc 2021
Commenté : ray d le 17 Déc 2021
Hi...im very new to Matlab,but was hoping i could get an answer to this....If i have a Matrix of N x M, of a set of values like below.How do i get a new logical Matrix.The logical values correspond to the column number,which are also the A values.
input
A = [1 3 4 9 12
2 5 6 9 11
1 4 5 10 12]
output 1 2 3 4 5 6 7 8 9 10 11 12
1 0 1 1 0 0 0 0 1 0 0 1
0 1 0 0 1 1 0 0 1 0 1 0
1 0 0 1 1 0 0 0 0 1 0 1
Thank you.

Réponse acceptée

Stephen23
Stephen23 le 17 Déc 2021
Modifié(e) : Stephen23 le 17 Déc 2021
A = [1,3,4,9,12;2,5,6,9,11;1,4,5,10,12]
A = 3×5
1 3 4 9 12 2 5 6 9 11 1 4 5 10 12
X = any((1:12)==permute(A,[1,3,2]),3)
X = 3×12 logical array
1 0 1 1 0 0 0 0 1 0 0 1 0 1 0 0 1 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 0 1 0 1
M = [1:12;+X]
M = 4×12
1 2 3 4 5 6 7 8 9 10 11 12 1 0 1 1 0 0 0 0 1 0 0 1 0 1 0 0 1 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 0 1 0 1
  1 commentaire
ray d
ray d le 17 Déc 2021
Works a treat.....thanks very much Stephen.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Operating on Diagonal Matrices 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