filtering out negative values and zeroes from .txt data file
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Vidhyashankar V
el 17 de Ag. de 2020
Comentada: Vidhyashankar V
el 18 de Ag. de 2020
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 .
Respuesta aceptada
Walter Roberson
el 18 de Ag. de 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 comentarios
Walter Roberson
el 18 de Ag. de 2020
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.
Más respuestas (1)
KSSV
el 17 de Ag. de 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 comentarios
Walter Roberson
el 18 de Ag. de 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?
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!