finding minimum value with index

15 ビュー (過去 30 日間)
JAVAD
JAVAD 2023 年 3 月 19 日
回答済み: Amith 2023 年 3 月 28 日
Hi
I have a matrix 3 dimensions. i,j,t(time). I try to find minimum for part of matrix when 85<j<170; 50<i<80 for each time step. In other words, the minimum of for all(one page).Also, I need in the location which i,j(index).
How can I do it?

採用された回答

Amith
Amith 2023 年 3 月 28 日
As per my understanding you wanted to know how you can find the minimum value and their corresponding indices for a submatrix in the range for i=(86,169) and j=(51,79) for every time step. Below is the code provided for performing the same.
%defined the timesize as 10.
timesize = 10;
%generated a matrix of random numbers.
matrix = randn(80,170,timesize);
index_x = zeros(1,timesize);
index_y = zeros(1,timesize);
minvalues = zeros(1,timesize);
for time = 1:timesize
%takes a submatrix for that particular time step
A = matrix(51:79, 86:169, time);
%finds the minimum value and index but as linear indices.
[minimum_values, index] = min(A, [], [1 2],'linear');
%storing minimum values
minvalues(time) = minimum_values;
%converts linear indices into subscripts (i.e into actual i,j indices)
[row, col] = ind2sub(size(A), index);
%adding the starting index as we have taken submatrix and have done
%operations on that
index_x(time) = row+51-1;
index_y(time) = col+86-1;
end
disp(index_x) %gives the minimum values x index
disp(index_y) %gives the minimum values y index
disp(minvalues) %provides the minimum values for the each time instance

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePattern Recognition and Classification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by