How to replace NaN values with 0 of a GRIDobject?

Hello
I have a raster and I imported it on Matlab as GRIDobject but it contains NaN and some values.
I want to change those NaN values with 0; and maybe if it is possible to create a logical GRIDobject
I have tried A(isnan(A))=0; command but is showing error because it isn't a matrix but a GRIDobject.
can anyone help me out this?
Thanks

3 Kommentare

Jonas
Jonas am 7 Jul. 2023
where did you find those GRIDobjects? a quick googling did not yield a suitable result
STREAMobj Create stream object (STREAMobj)
Syntax
S = STREAMobj(FD,W)
Description
An instance of stream object encapsulate the information on geometry
and connectivity of a stream network based on the flow direction of a
digital elevation model and a logical raster that indicates the
position of streams. STREAMobj provides access to various methods
that investigate properties of a stream network and associated data.
Input arguments
FD instance of flow direction object (FLOWobj)
W logical grid (GRIDobj) that indicates stream locations (e.g.
obtained from thresholding the flow accumulation raster)
My goal is to use a streamnetwork shapefile as W to create a new streamnetwork S. I rasterized it and I modified it to create a logical raster; then I import it to Matlbal as a GRIDobj. The problem comes out with the function S = STREAMobj(FD,W) because of the presence of NaN values instead of value 0.
Thank you!
Dear Rossana,
it might be better to ask TopoToolbox-related questions here: https://github.com/wschwanghart/topotoolbox/discussions
Best regards, Wolfgang

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Cris LaPierre
Cris LaPierre am 9 Jul. 2023
Bearbeitet: Cris LaPierre am 9 Jul. 2023
The TopoToolbox is not created by MathWorks.
A quick look at the list of toolbox functions leads me to suggest looking into the isnan or inpaintnans functions that come with the toolbox. Both accept a GRIDobj as input.
function I = isnan(DEM)
% returns array elements that are NaNs as logical grid
%
% Syntax
%
% I = isnan(DEM)
%
% Description
%
% overloaded isnan for GRIDobj.
.
function DEM = inpaintnans(DEM,varargin)
%INPAINTNANS Interpolate or fill missing values in a grid (GRIDobj)
%
% Syntax
%
% DEMf = inpaintnans(DEM,type)
% DEMf = inpaintnans(DEM,type,k)
% DEMf = inpaintnans(DEM,type,k,conn)
% DEMf = inpaintnans(DEM,DEM2)
% DEMf = inpaintnans(DEM,DEM2,method)
% DEMf = inpaintnans(DEM,DEM2,'tt','fit',1,'eps',20)
%
% Description
%
% inpaintnans fills gaps in a grid (GRIDobj) generated by measurement
% errors or missing values. The user may choose between different
% techniques to fill the gaps. Note that the algorithm fills only
% pixels not connected to the DEM grid boundaries.

Community Treasure Hunt

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

Start Hunting!

Translated by