1D array to 2D array positions
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Eduardo Santos
am 30 Apr. 2019
Bearbeitet: James Tursa
am 30 Apr. 2019
I would like to 'convert' a 1D array to a 2D matrix considering the value inside the array as:
A =
1 3 4 4 3
B =
0 0 0 0 0
0 0 1 1 0
0 1 0 0 1
0 0 0 0 0
1 0 0 0 0
Can you suggest a very fast way to do that?
The row number is fixed at 5 here (a known value).
0 Kommentare
Akzeptierte Antwort
James Tursa
am 30 Apr. 2019
Bearbeitet: James Tursa
am 30 Apr. 2019
n = 5;
B = zeros(n,size(A,2));
B(sub2ind(size(B),n+1-A,1:size(A,2))) = 1;
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Types finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!