find the location of minimum value
3 ビュー (過去 30 日間)
古いコメントを表示
i have matrix with 4 variables, A=mintemp(a,b,c,d). i have find the minimum value especially at V=mintemp(:,:,1,1) dan the minimum value is out=min(V(:)). now, how to find the location / the coordinates the minimum value ?
if the matrix just two variables, i can the identify the coordinates with this :
A=magic(4);
out=min(A(:));
aa=1;
bb=1;
for xx=1:4
for yy=1:4
if(out==1)
aa=xx;
bb=yy;
end
end
end
i really have no idea if the matrix have 4 variables.
1 件のコメント
Azzi Abdelmalek
2013 年 2 月 14 日
What is mintemp? and what do you mean by: the matrix have 4 variables.
採用された回答
Azzi Abdelmalek
2013 年 2 月 14 日
編集済み: Azzi Abdelmalek
2013 年 2 月 14 日
Edit
A=rand(4,4,4,4)
[ii1,ii2,ii3,ii4]=size(A)
count=0
id=zeros(ii3*ii4,4);
for k=1:ii3
for p=1:ii4
count=count+1;
v=A(:,:,k,p);
[val,idx]=min(v(:));
[id1,id2]=ind2sub(size(v),idx);
minval(count)=val;
idx1(count)=id1;
idx2(count)=id2;
idx3(count)=k;
idx4(count)=p;
id(count,:)=[id1 id2 k p] % correspondant indices
end
end
11 件のコメント
Azzi Abdelmalek
2013 年 2 月 14 日
編集済み: Azzi Abdelmalek
2013 年 2 月 14 日
Look at the edited answer. It's the variable id
その他の回答 (2 件)
Thorsten
2013 年 2 月 14 日
編集済み: Thorsten
2013 年 2 月 14 日
R = rand(4,4,4,4);
for i = 1:size(R, 3)
for j = 1:size(R, 4)
[min_val(i, j) min_ind(i, j)] = min(flatten(R(:,:, i, j)));
[a b] = ind2sub(size(R), min_ind(i,j));
minserial(end+1, :) = [i j a b];
end
end
With the convenience function flatten defined as
function y = flatten(x)
y = x(:);
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!