How to fix a number equal to null in MATLAB

Hello
I have a lot values (equal to -999.25) in my data columns. I want that matlab read these values (-999.25) as zero when ever I load or run my data on MATLAB. How can I fix this problem? Please help

 Respuesta aceptada

源樹 上林
源樹 上林 el 13 de Ag. de 2020

0 votos

a = [ 1 2 3 -999.25 -999.25 4 5]
a(a == -999.25) = 0

7 comentarios

Nisar Ahmed
Nisar Ahmed el 13 de Ag. de 2020
Hello,
Thank you for the answer but it is still not working. Do I need to write it as same as you did
a = [ 1 2 3 -999.250000 -999.250000 4 5]
a(a == -999.250000) = 0
or need to write as
a = [-999.250000]
a(a == -999.250000) = 0
a = your numeric array
a(a == -999.250000) = 0
Nisar Ahmed
Nisar Ahmed el 13 de Ag. de 2020
Oh, right
I have 10 numeric arrays and each array have more than 10000 numerical values. In that case how I can write this code?
Thanks
10 different statements each along the same lines but different variable names. Create a small function if you want.
a = clew(a) ;
b = clew(b) ;
function A = clew(A)
A(A==-999.25) = 0;
Question: can the arrays have negative numbers other than -999.25 in them? If the magic number is the only possible negative number then there is an easier way:
a = max(0,a);
b = max(0,b);
Nisar Ahmed
Nisar Ahmed el 13 de Ag. de 2020
Hi Walter,
Thank you, I have 10 arrays and -ve meaurements are also possible for some arrays. However, -999.25 means null value that's I just need to fix it and I fixed it for one array (say DTP) as
a = DTP;
a(DTP = -999.25) = NaN;
DTP=a;
Do I need to repeat this code for each array? Or is there any way to fix it in all arrays with 1,2 steps?
DTP = clew(DTP);
DRZ = clew(DRZ) ;
function A = clew(A)
A(A==-999.25) = nan;
So you would have 10 lines of assignment, one for each variable.
Yes it is possible to do it in fewer lines with more confusing code.
But better would have been to store all of the arrays in the same variable, such as a multidimensional array or cell array or struct. Any of those could have all fields processed easily, like
Dats = structfun(@clew, Dats, 'uniform', 0)
Nisar Ahmed
Nisar Ahmed el 13 de Ag. de 2020
Roberson,
Thanks

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 13 de Ag. de 2020

Comentada:

el 13 de Ag. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by