how to remove the NaN values from a dataset?

23 ビュー (過去 30 日間)
Sreeraj R
Sreeraj R 2021 年 11 月 24 日
回答済み: Image Analyst 2021 年 11 月 24 日
hi everyone
i have made a dataset which has values in my study region and rest of the area has NaN values. how do i remove the Nan values so that i get only my study area. i have done this to crop my study area. the current dimensions of the dataset is 450x4173x34, so after removing the NaN values the dimensions also should change. kindly let me know how to do this.
i tried using isnan but the output was in 1 dimension. i need my output in 3 dimensions.

採用された回答

KSSV
KSSV 2021 年 11 月 24 日
Read about isnan,
A = [1 2 NaN 2 NaN rand] ;
idx = isnan(A) ;
A(idx) = [] % remove NaNs
If you try to remove NaN's from matrix, the result will be a column array and you may not want this. So try to fill NaN's with legit values either using fillmissing or ScatteredInterpolant.

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 11 月 24 日
You could try regionfill(). But since it only operates on 2-D images, you'd have to fill it in slice by slice.

Community Treasure Hunt

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

Start Hunting!

Translated by