Replacing NaN cell array values with empty values

20 visualizaciones (últimos 30 días)
Jared
Jared el 2 de Dic. de 2014
Comentada: Jared el 2 de Dic. de 2014
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

Respuesta aceptada

Guillaume
Guillaume el 2 de Dic. de 2014
Editada: Guillaume el 2 de Dic. de 2014
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 comentario
Jared
Jared el 2 de Dic. de 2014
Thanks both for your responses. That's what I was looking for.
JK

Iniciar sesión para comentar.

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 2 de Dic. de 2014
Editada: Azzi Abdelmalek el 2 de Dic. de 2014
A=[8 10 5 -9 NaN];
A=transpose(A);
A=num2cell(A)
A{5,1}=' '
%or better
A{5,1}=[]

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by