create a matrix with numbers from vector
Mostra commenti meno recenti
i have a vector as
v = [ 1 1 1 2 2 2 3 3 4]
i wanted to create a new matrix as
M = [
1 1 1 0 0 0 0 0 0;
0 0 0 1 1 1 0 0 0;
0 0 0 0 0 0 1 1 0;
0 0 0 0 0 0 0 0 1];
how to do it?
Risposta accettata
Più risposte (2)
madhan ravi
il 13 Feb 2019
Simpler:
M = +(v==unique(v).')
2 Commenti
Stephen23
il 13 Feb 2019
+1 very tidy. I like that.
madhan ravi
il 13 Feb 2019
Thank you!
KSSV
il 13 Feb 2019
N = zeros(3,3,3) ;
for i = 1:3
N(i,:,i) = 1 ;
end
M = reshape(N,3,[])
Categorie
Scopri di più su Dynamic System Models in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!