Find and replace a specific value in a table

208 visualizaciones (últimos 30 días)
Pablo SERIS el 21 de Abr. de 2022
Respondida: Siddharth Bhutiya el 30 de Mzo. de 2023
Hello, I have a table with over 15000 rows and 100 columns. I want to plot the values in columns but I need to turn some of them that are set to -9999 to NaN. And there are -9999 in all my columns( my columns are named)/
I would like to use something like that :
table(table==-9999)=NaN
But I know that I can't use comparator with a whole table so I have to add index :
table(table(:,:)==-9999)=NaN
But it's still not working.
Is there an index that take all columns? Or maybe another solution more simple?
Thank you!
0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Image Analyst el 21 de Abr. de 2022
Editada: Image Analyst el 21 de Abr. de 2022
You forgot to attach your table so I had to create one.
% Create table data because OP forgot to attach his.
v1 = rand(100, 1);
v2 = rand(100, 1);
v1(1:10) = -9999;
v1(end-4:end) = -9999;
v2(1:15) = -9999;
v2(end-14:end) = -9999;
t = table(v1, v2, 'VariableNames', {'Column1', 'Column2'})
% METHOD 1: uSING table2array()
variableNames = t.Properties.VariableNames;
m = table2array(t);
m(m==-9999) = nan;
tFixed = table(m(:, 1), m(:, 2), 'VariableNames', {'Column1', 'Column2'});
% METHOD 2: USING FOR LOOP
% Now we have our table and we can begin replacing -9999 with NaN.
for col = 1 : width(t)
map9999 = t{:, col} == -9999;
t{map9999, col} = nan;
end
1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Pablo SERIS el 22 de Abr. de 2022
Thank you it works!

Iniciar sesión para comentar.

Más respuestas (2)

Siddharth Bhutiya el 30 de Mzo. de 2023
You could use standardizeMissing to do this.
t = table([1;-9999;3],[-9999;NaN;4],[NaN;4;5])
t = 3×3 table
Var1 Var2 Var3 _____ _____ ____ 1 -9999 NaN -9999 NaN 4 3 4 5
t = standardizeMissing(t,-9999)
t = 3×3 table
Var1 Var2 Var3 ____ ____ ____ 1 NaN NaN NaN NaN 4 3 4 5
0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

David Hill el 21 de Abr. de 2022
m=table2array(yourTable);%assuming your table is all numbers of the same type
m(m==-9999)=nan;
%then just plot from the matrix
0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Identification 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!

Translated by