filtering out negative values and zeroes from .txt data file

15 views (last 30 days)
I have some .txt files with me and there are zeros and negtive values in some columns I would like to filter out the data like just exclude the zeros and negative values and get the data in the workspace. How should I do that. The txt file is attached below. Thanks in advance for your help .

Accepted Answer

Walter Roberson
Walter Roberson on 18 Aug 2020
varmask = varfun(@isnumeric, YourTable, 'output', 'uniform');
as_numeric = YourTable{:,varmask};
good_data_mask = all(as_numeric > 0, 2);
reduced_table = YourTable(good_data_mask, :);
This removes an entire row if any non-positive value is found anywhere in the row.
  3 Comments

Sign in to comment.

More Answers (1)

KSSV
KSSV on 17 Aug 2020
Let A be an array..you can remove the negative values using:
A(A<0) = [] ; % this remove all negative values
A(A<=0) = [] ; % this will remove negative values and zeros
A = A(A>0) ; % This will pick all positive values
s = sign(A) ; % this will sign of values 1 for positive and -1 for negative
  5 Comments
Walter Roberson
Walter Roberson on 18 Aug 2020
first_column_data = x130_Gmod12_SS.Data{:,1};
WIth the () brackets you get a sub-table, not the contents of the variable.
However this does not explain why x130_Gmod12_SS does not permit dot indexing. What is class(x130_Gmod12_SS) ?
eval(sprintf('%s = data.%s', x{1}, x{1}));
is it possible to remove all the zeroes and negative values all at once?.
You have some columns that are non-numeric. Should only the numeric columns be processed?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!