create a new matrix from a vector
Ältere Kommentare anzeigen
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 Kommentare
madhan ravi
am 13 Mär. 2019
Why do you think transpose() should not be used?
Elysi Cochin
am 13 Mär. 2019
KSSV
am 13 Mär. 2019
It works with newV also....you need not to change any part of code.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!