How to add a row vector for indexing
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ashraf Sherif
am 12 Feb. 2019
Kommentiert: Ashraf Sherif
am 13 Feb. 2019
How to add a row vector for indexing C by M when my M is 4 dimensional ? any help will be thankful.
F=random('exp',1,3,3,4);
C=F*100
M=bsxfun(@times, C./cumsum(C,3) , reshape(1:4,1,1,[]) );
[vec,idx] = max(M,[],1); % value and row index of max in each column.
S = size(M); % size of input array.
idx = idx + S(1)*(0:S(2)-1); % convert row index into linear index !
C(idx); % use linear index to get elements of C.
2 Kommentare
Jan
am 12 Feb. 2019
What exactly is your question? What do you want to add to what? Does the posted code do what you expect? If not, what do you want to change?
Akzeptierte Antwort
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!