mHelpMe
mHelpMe

Reputation: 6668

Convert MATLAB NaN to SQL Null in a cell array

I have a large cell array. I have 3 columns which are numerical. Some of the rows in these columns are NaN. This causes an issue when I upload the data to SQL Server (I do not wish to use the matlab function insert).

So far I have tried the below,

 export_full = strrep(export_full(:, 6:9),'NaN','NULL');

which return the error message

Cell elements must be character arrays.

Can I use indexing to solve this problem if so how? Performance would be an issue too as its quite a large cell array.

Edit

My cell array is a 10000 x 10 cell column 1 is string column 2 is string column 3 is date column 4 to 10 is numerical

Upvotes: 1

Views: 861

Answers (1)

Dan
Dan

Reputation: 45752

I think this should do the trick (credit goes to: http://www.mathworks.com/matlabcentral/newsreader/view_thread/283735)

ind = cellfun(@(x) any(isnan(x(:))), export_full)
export_full(ind) = {'NULL'};

Upvotes: 1

Related Questions