Replacing NaN cell array values with empty values

19 ビュー (過去 30 日間)
Jared
Jared 2014 年 12 月 2 日
コメント済み: Jared 2014 年 12 月 2 日
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 件のコメント
Jared
Jared 2014 年 12 月 2 日
Thanks both for your responses. That's what I was looking for.
JK

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by