필터 지우기
필터 지우기

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 CenterFile Exchange에서 Creating 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