Matrix Indexing
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have an index matrix.
idx = [1 5 ; 3 7 ]
The goal is to get a matrix like this:
1 0
0 0
0 1
0 0
1 0
0 0
0 1
Indexing the matrix like
a(idx) = 1;
doesn't work. Right now I use a loop, but I am not sure if this is the best way.
0 Kommentare
Akzeptierte Antwort
Matt Fig
am 4 Feb. 2011
A = zeros(max(idx(:)),size(idx,1));
A(sub2ind(size(A),idx,cumsum(ones(size(idx))))) = 1
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!