How to use argmax in 3D matrices?
Show older comments
I am new to Matlab. I have a 3D Matrix say M(x,y,k). I need to find a 2D Matrix D(x,y) such that D(x,y) has the highest values of M{k}, OR :
D(x,y) = argmax( M(x,y,k) )
Answers (1)
John D'Errico
on 21 Nov 2017
Um, read the help for max? If you are that much of a beginner, then you should start out by reading the getting started tutorials.
A = rand(2,3,4)
A(:,:,1) =
0.18558767031022 0.367693411562176 0.949304929946452
0.125794384998311 0.825831885926276 0.798028693039495
A(:,:,2) =
0.46387357998381 0.702317087838322 0.232451965165933
0.614238220285913 0.526032548266009 0.106738218529651
A(:,:,3) =
0.956797183291321 0.0699667778161488 0.611150494847145
0.662423347108867 0.892792624243972 0.585063797123285
A(:,:,4) =
0.852340132245934 0.377986141768676 0.490544298291429
0.659436276865168 0.738620002236467 0.0429808680184772
[M,ind] = max(A,[],3)
M =
0.956797183291321 0.702317087838322 0.949304929946452
0.662423347108867 0.892792624243972 0.798028693039495
ind =
3 2 1
3 3 1
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!