Minimum value and Indices by removing same indices combination form the MAT file
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
1 comentario
Prateekshya
el 17 de Ag. de 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.
Respuestas (1)
Pratyush Swain
el 31 de Ag. de 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
Hope this example helps you in resolving issue. For further reference you can refer to https://in.mathworks.com/help/matlab/ref/min.html
Ver también
Categorías
Más información sobre Function Creation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!