How to find result in the same metric ??

2 views (last 30 days)
yanisa ketsuwan
yanisa ketsuwan on 19 Jun 2021
Commented: Walter Roberson on 20 Jun 2021
It wasn’t what I thought it would be. The final result in the variable "fr" has the same value or incorrect . what should i do?
x = rand(100, 2);
col1 = x.data(:,1);
col2 = x.data(:,2);
n = 2;
val = zeros(n,1);
fr = zeros(n,2);
for i=1:n
[val(i) , idA] = min(col2);
col2(idA) = []; % remove the first value
end
fr=col1(idA);
I would like row and colum result of variable fr is like variable val?

Answers (1)

Walter Roberson
Walter Roberson on 19 Jun 2021
[val(i) , idA] = min(col2);
You are taking min() of the same thing each time, so you get the same result each time.
  2 Comments
yanisa ketsuwan
yanisa ketsuwan on 20 Jun 2021
yes, This problem could be solved by col2(idA) = [].
But I get the same answer when browsing. Row and column in variable col1. What should I do?
Walter Roberson
Walter Roberson on 20 Jun 2021
Consider using mink to find the indices of the n minimum entries of the first column and use the indices to index the rows

Sign in to comment.

Categories

Find more on Descriptive Statistics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!