Removing nan values inside cells of a cell array

I have a cell array that looks like this:
Cells in column 1 would look similar to this with nan values mixed values of salinity:
Column 2 is depth values from 1 and onwards, like this:
Is there any way to remove the nan values in column 1 and the corresponding values in column 2?
I've been trying to search for it but haven't found a way that I could get to work.

 Accepted Answer

Jaskabara - you can use isnan to determine which elements are NaN in your array. This function returns a logical array containing 1 (true) where the elements of A are NaN, and 0 (false) where they are not. For example,
column1 = randi(255,15,1); % generate two 15x1 columns of random integers
column2 = randi(255,15,1);
column1(5) = NaN; % set a couple of elements in column1 to NaN
column1(11) = NaN;
nanElements = isnan(column1); % determine indices corresponding to NaN elements
column1(nanElements) = []; % remove NaN elements from column1
column2(nanElements) = []; % remove corresponding elements from column2

2 Comments

This answer is not relevant to the question., The quesion asked to remove NaN from cell array

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!