how to remove NAN from a double inside a cell array?

31 views (last 30 days)
Farshid Daryabor
Farshid Daryabor on 23 Jan 2020
can some one how can I remove NAN from a double inside a cell array (attached file)?
  5 Comments
Farshid Daryabor
Farshid Daryabor on 23 Jan 2020
Each columns are corresponds to a latitude and longitude to introduce seawater temperature profiles. I want to keep the matrix structure as is, but delete the NaNs from each column.
I tried to interpolate NaNs, but problem is converting cell to number, I used the following function, encountering with error, Out = cellfun(@cell2mat, (inpaint_nans(mycelldata,0)) ); Any comment to improve.

Sign in to comment.

Answers (2)

Hamdan Almusaibeli
Hamdan Almusaibeli on 7 Apr 2021
>> uq =
1×3 cell array
{3×3 double} {7×3 double} {7×3 double}
>> uq{1}
ans =
0.5000 0.3333 0.0500
2.5000 0.3333 0.0500
2.5000 0.3333 0.0500
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
uq{1}(isnan(uq{1}(:,1)),:) = []
>> uq{1}
ans =
0.5000 0.3333 0.0500
2.5000 0.3333 0.0500
2.5000 0.3333 0.0500

KSSV
KSSV on 23 Jan 2020
You can fill the nans using fillmissing. Also you can do interpolation ang the values at the places of nan. Read about interp1.
  6 Comments
Guillaume
Guillaume on 23 Jan 2020
Note that this is a solution to my second bullet point.
A better way (probably faster) to do the above is:
newA = A(~any(isnan(A), 2), :)

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!