filtering out negative values and zeroes from .txt data file

38 次查看(过去 30 天)
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 .

采纳的回答

Walter Roberson
Walter Roberson 2020-8-18
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 个评论
Walter Roberson
Walter Roberson 2020-8-18
What would you mean by "remove" in that case? Do you want the row removed? Do you want the column removed? Do you want the value replaced by nan? Do you want a space to replace the entry?
If you want a space to replace the entry it will be necessary to convert the column to a cell array of character vectors and put the empty character vector in that location. MATLAB does not have any way to mark an element in a numeric array as being "missing" in a sense that the output for the location is to be emptiness.

请先登录,再进行评论。

更多回答(1 个)

KSSV
KSSV 2020-8-17
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 个评论
Vidhyashankar V
Vidhyashankar V 2020-8-17
the data in the work space is 1440*75 (table), is it possible to remove all the zeroes and negative values all at once?.
Walter Roberson
Walter Roberson 2020-8-18
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by