How to value value NaN in a 2d matrix?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Dimitrios
el 2 de Oct. de 2014
Respondida: Andrei Bobrov
el 2 de Oct. de 2014
I have a 2d matrix with some NaN. how to value them? I give some figure to be more understandable:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145581/image.png)
It can be seen that there 2-3 values equal to NaN. I was wondering how to interpolate them with the rest values.Thanks in advance.
0 comentarios
Respuesta aceptada
Andrei Bobrov
el 2 de Oct. de 2014
please use scatteredInterpolant, example:
a = randi([6 10],30,20);
a(randperm(numel(a),20)) = nan; % a - your 2d array with nan's
[r,c] = ndgrid(1:size(a,1),1:size(a,2));
l0 = ~isnan(a);
F = scatteredInterpolant(r(l0),c(l0),a(l0))
surf(a)
a2 = F(r,c);
figure,surf(a2)
0 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre NaNs 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!