filter parameters using if else

11 ビュー (過去 30 日間)
Federico Caruso
Federico Caruso 2016 年 7 月 20 日
コメント済み: Federico Caruso 2016 年 7 月 20 日
Hi guys I have this problem. I have a .txt file which is 208000 rows and 2 columns. The 1st column represent the x-axis and the second is the y-axis, as you can see there are multiple y values for the same x. I would like that my script would select only one value of x and the maximum y value for that x. I am trying to do this using if else but I fail somewhere because it doesn't delete the worst values. This is my script:
clc
clear all
Y1 = importdata('Y_nitro_stke_neqwf.txt');
B = sortrows(Y1);
[n,m] = size(B);
new = zeros(size(B));
new(1,1) = B(1,1);
new(1,2) = B(1,2);
for i = 2:n
if B(i,1) > new(i-1,1)
new(i,1) = B(i,1);
new(i,2) = B(i,2);
elseif B(i,1)== new(i-1,1)
new(i-1,2) = B(i,2);
new(i,1) = B(i,1);
new(i,2) = B(i,2);
end
end
Thanks a lot if you can help me

採用された回答

Thorsten
Thorsten 2016 年 7 月 20 日
編集済み: Thorsten 2016 年 7 月 20 日
[a, ~, c] = unique(B(:,1));
Bnew = [a arrayfun(@(x) max(B(c==x,2)), 1:numel(a))']
  1 件のコメント
Federico Caruso
Federico Caruso 2016 年 7 月 20 日
Thanks a lot!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by