MATLAB Answers

How to find indices of certain values from dataset using a loop

1 ビュー (過去 30 日間)
Iliqe
Iliqe 2021 年 1 月 23 日
コメント済み: Iliqe 2021 年 1 月 25 日
Hi gyus, I am a beginner in coding.
My problem is that I want to find indices of values using a loop, but having and error.
Could anyone explain what is wrong with loop and give a solution??? (file which I use is attached)
The general idea is to find 5 smallest values and its indices from the dataset (column "Lag").
clear;
data=xlsread('kNN_300_y_pred_wd XYZValue + lag.csv');
newarray = sort(data(:,5));
k=5;
values = newarray(1:k);
for i=1:k
index = find(values==data(:,5));
end

採用された回答

Andreas Apostolatos
Andreas Apostolatos 2021 年 1 月 23 日
Hello,
You can use the following code snippet for your purposes:
clear;
data = readtable('kNN_300_y_pred_wd XYZValue + lag.csv');
newarray = sort(data{:,5});
k=5;
values = newarray(1:k);
for i=1:k
[~, indices] = ismember(values, data{:,5});
end
Note that I used 'readtable' instead of 'xlsread' to read-in the csv-file.
I hope that helps.
Kind Regards,
Andreas
  3 件のコメント
Iliqe
Iliqe 2021 年 1 月 25 日
Many thanks to you Andreas.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by