Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Aamir
Aamir le 17 Mai 2023
Modifié(e) : Aamir le 14 Fév 2024
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 commentaire
Prateekshya
Prateekshya le 17 Août 2023
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.

Connectez-vous pour commenter.

Réponses (1)

Pratyush Swain
Pratyush Swain le 31 Août 2023
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 commentaire
Aamir
Aamir le 6 Sep 2023
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by