MATLAB Answers

How to delete columns if there is'nt enough data?

8 views (last 30 days)
Gerrit Liedtke
Gerrit Liedtke on 7 May 2018
Edited: Ameer Hamza on 7 May 2018
Hi,
I want to delete some columns of my data if there are less than 13 observations in it. If I would use rmmissing and 'MinNumMissing' then the column would be deleted if there are 13 values missing.
Thanks for help.

  3 Comments

Bob Nbob
Bob Nbob on 7 May 2018
Since you can't have uneven array column lengths, what values do you have in place of the missing observations?
Bob Nbob
Bob Nbob on 7 May 2018
I would suggest using a for loop with an if statement that looks for nan values.
for k = 1:size(data,2);
if sum(~isnan(data(:,k)))<13;
data = [data(:,1:k-1),data(:,k+1:end)];
end
end
You would need to have some check for first and last rows, but that should get you started on what I was thinking about.

Sign in to comment.

Answers (2)

David Fletcher
David Fletcher on 7 May 2018
prunedData = rmmissing(dataMatrix,2,'MinNumMissing',13)

  0 Comments

Sign in to comment.


Ameer Hamza
Ameer Hamza on 7 May 2018
Edited: Ameer Hamza on 7 May 2018
Do it as follow
data = data(:, sum(~isnan(data))>=13)

  0 Comments

Sign in to comment.

Sign in to answer this question.