maximum value in a 3d matrix

14 ビュー (過去 30 日間)
Bola
Bola 2013 年 9 月 14 日
write a MATLAB script that finds the maximum value and its M and N indexes in each of the P pages. (i.e. the max on EACH of the pages, not the single max among all the pages. You will find P maxima and P pairs of indexes.
This is a 3d matrix (m*n*p) and i want to find the maximum value on each "page", as well as its m by n indexes on each page. can anyone please help?
  4 件のコメント
Bola
Bola 2013 年 9 月 14 日
no,lets say if i have a 100*100*100 array and i find the largest value on each "page" that would mean i have 100 numbers. If i find the indexes of those 100 numbers i have 100*100 numbers i would like to plot those indexes
Image Analyst
Image Analyst 2013 年 9 月 14 日
編集済み: Image Analyst 2013 年 9 月 14 日
Assuming "page" means a "slice" or "plane" in the "z" (third) dimension, then for each "page" you'll have one or more max values. Let's say you have only one per page just to make it easy. So you have 100 maxes. And each max element will have an x, a y, and a z index. So you can store these in a 100 by 4 array where each row is
[maxValue, x, y, z]
So that's 100*4 = 400 values, or 300 if you're not including the values of the element and just record the x,y,z values, or even 200 if you just have 100 rows and the x and y locations for that row (where the row is the page number). So how do you get 100*100 = ten thousand values?
So, assuming you have the 100 locations (300 x,y,z values) how do you want to plot them? With plot3() or scatter3()?

サインインしてコメントする。

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 14 日
for k=1:size(A,3)
a=A(:,:,k);
[maxv,idx]=max(a(:));
[ii,jj]=ind2sub([size(A,1) size(A,2)],idx);
out{k}=[maxv ii jj]
end
celldisp(out)
  1 件のコメント
Bola
Bola 2013 年 9 月 14 日
thank you, this works beautifully, but i would also like to now plot ii against jj. When i do so, i get a blank graph.

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2013 年 9 月 14 日
s = size(A);
[v,ii] = max(reshape(A,[],s(3)));
[i1 j1 ] = ind2sub(s(1:2),ii);
out = [v;i1;j1;1:s(3)]';

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by