Replacing NaN cell array values with empty values

19 次查看(过去 30 天)
Hi all,
I've tried to figure this out (and looked at past forum posts) but I haven't been able to determine how to replace NaN values in a cell array with an empty/NULL value while retaining the size of the cell array. For example:
A=[8 10 5 -9 NaN];
A=transpose(A);
A=num2cell(A);
A(5,1)='';
This code ends up deleting the 5th element so that my array is now 4x1.
The background for why I'm trying to do this is that I'm exporting a number of different series into an Access database and I want each series to be of the same length. Unfortunately Access won't let me accomplish this by exporting NaNs and numbers into the database because it doesn't accept mixed data types. So I'm trying to find a way to keep the size of each series the same by replacing the NaNs w/ something that Access will treat as a null value (of course open to any other ideas to accomplish my ultimate objective).
Thanks,
JK

采纳的回答

Guillaume
Guillaume 2014-12-2
编辑:Guillaume 2014-12-2
You need to understand the difference between {} and () indexed when using cell array.
{} returns the content of the indexed cell(s). It is of the same type as whatever is in the cell
() returns the cell(s) themselves. It always is a cell array.
Therefore
A(5,1) = []; %or A(5,1) = '';
deletes the cell,
A{5,1} = []; %or A{5,1} = '';
replaces the content of the cell by an empty matrix.

更多回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2014-12-2
编辑:Azzi Abdelmalek 2014-12-2
A=[8 10 5 -9 NaN];
A=transpose(A);
A=num2cell(A)
A{5,1}=' '
%or better
A{5,1}=[]

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by