create a new matrix from a vector
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Elysi Cochin
le 13 Mar 2019
Commenté : madhan ravi
le 13 Mar 2019
create a new matrix from
v = [1 1 1 2 2 2 3 3 4];
u=unique(v);
R=arrayfun(@(x)v==u(x),1:numel(u),'un',0);
M=+vertcat(R{:})
what if my matrix is
newV = [1; 1; 1; 2; 2; 2; 3; 3; 4];
what is the change i need to make without transposing the vector newv, to get the output M with newV
i used horzcat, but still without transposing, i'm not able to get result as M
3 commentaires
Réponse acceptée
madhan ravi
le 13 Mar 2019
R=arrayfun(@(x)reshape(newV,1,[])==u(x),1:numel(u),'un',0);
1 commentaire
madhan ravi
le 13 Mar 2019
Alternative:
+(reshape(newV,1,[])==unique(newV))
Plus de réponses (0)
Voir également
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!