How to delete columns from a matrix, conditionally?

3 ビュー (過去 30 日間)
Andi
Andi 2021 年 11 月 24 日
コメント済み: Andi 2021 年 11 月 24 日
My data matrix consists of 400 colomns (about 25000 rows). Data set consists of number and NaN. I want to delete the columns having less than 100 data points.
My attempt is as below:
clear all
clc
%a=importdata('test_file.txt');
data=load('DATA_0.01.csv');
%My attempt
for k = 1:size(data,2);
if sum(~isnan(data(:,k)))<100;
data = [data(:,1:k-1),data(:,k+1:end)];
end
end

採用された回答

Jan
Jan 2021 年 11 月 24 日
編集済み: Jan 2021 年 11 月 24 日
keep = sum(~isnan(data), 1) >= 100;
data = data(:, keep);
Your approach does not work, because the matrix data is changed, but the counter k is not adjusted accordingly. With a loop:
remove = true(1, size(data, 2));
for k = 1:size(data,2);
remove(k) = sum(~isnan(data(:,k))) < 100;
end
data(:, remove) = [];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by