フィルターのクリア

Minimum value and Indices by removing same indices combination form the MAT file

2 ビュー (過去 30 日間)
Aamir
Aamir 2023 年 5 月 17 日
編集済み: Aamir 2024 年 2 月 14 日
I need guidance regarding getting the Minimum or Maximum values each time for different indicies. I have attached a DataArray2Filter for your reference. The *.mat file has 1728 rows and 14 columns and the rows are (Num_Observation)^Iterations and iterations are [1,3,5] only. This data file is for 3 iterations [12^3].
I am checking minimum value based on first Column and remove the rows based on the indicies of Column in conjuction with Column 5 and 6. I want to repeat all this till I get the minimum values equal to Num of Iterations.
I tried the code below to check the minimum value but it removed all other columns. I want to remove the rows based on the index of column 1, colum 5 and column 6.
Since I want unique indicies in each time. Kindly guide me how to find keep all other columns when removing the rows based on indices.
array = load('DataArray2Filter.mat');
minValue = ones*inf(size(array,1),1);
minIndices = ones*inf(size(array,1),1);
counter = 0;
while true
counter = counter + 1;
% Find the minimum value and its indices
minValue(counter) = min(array(:,1));
minIndices(counter) = find(array(:,1) == minValue);
val_column5 = array(minIndices(counter),5)
val_column6 = array(minIndices(counter),6)
% Remove all occurrences of the minimum value
array = array((array(:,1) ~= minValue) && (array(:,5) ~= val_column5) && (array(:,6) ~= val_column6));
% Check if there are any elements left in the array
if isempty(array)
break; % Exit the loop if the array is empty
end
% Display the minimum value and its indices
disp("Minimum value: " + minValue(counter));
disp("Indices: " + num2str(minIndices(counter)));
end
Error using min
Invalid data type. First argument must be numeric or logical.
  1 件のコメント
Prateekshya
Prateekshya 2023 年 8 月 17 日
I understand that you are trying to find out the minimum value and index in each iteration by avoiding duplicate entries. However, since many of the variables are not very clear, please provide the entire code so that I can understand the problem better. Also, please explain what is slot and how they are significant.

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

回答 (1 件)

Pratyush Swain
Pratyush Swain 2023 年 8 月 31 日
Hey Aamir,
I observed you want to find the minimum value and indices of an array in each iteration followed by removal of the minimum indices.
Please refer to the example code snippet:
% Example array where we perform the identification and deletion process iteratively.
array = [5, 3, 2, 1, 3, 2, 4, 1, 2];
while true
% Find the minimum value and its indices
minValue = min(array);
minIndices = find(array == minValue);
% Remove all occurrences of the minimum value
array = array(array ~= minValue);
% Check if there are any elements left in the array
if isempty(array)
break; % Exit the loop if the array is empty
end
% Display the minimum value and its indices
disp("Minimum value: " + minValue);
disp("Indices: " + num2str(minIndices));
end
Minimum value: 1
Indices: 4 8
Minimum value: 2
Indices: 3 5 7
Minimum value: 3
Indices: 2 3
Minimum value: 4
Indices: 2
Hope this example helps you in resolving issue. For further reference you can refer to https://in.mathworks.com/help/matlab/ref/min.html
  1 件のコメント
Aamir
Aamir 2023 年 9 月 6 日
Thanks for your reply.
I tried this code but I am getting the same value again and again. Might be indexing is an issue for. I am looking into the issue and will update you.

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by