conversion of a dataset array

1 visualización (últimos 30 días)
Matthew
Matthew el 22 de Abr. de 2014
Comentada: Andreas Justin el 23 de Abr. de 2014
Hi.
I have the following dataset:
ID SP MD FI
'1234' 'BBB-' 'Baa3' []
'1235' [] [] 'A-'
'1236' 'BB' 'Ba1' 'BB+'
'1237' 'A' 'A3' []
This table was created from a cell to dataset.
Now I know it looks like it but ID is not a string (I think) and I'm trying to do a str2num and this is failing.
Does anyone know how to convert ID into a number?
  1 comentario
Andreas Justin
Andreas Justin el 22 de Abr. de 2014
Editada: Andreas Justin el 22 de Abr. de 2014
str2double?
ds = cell2dataset({'ID';'123';'1234'});
str2double(ds.ID)
ans =
123
1234

Iniciar sesión para comentar.

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 22 de Abr. de 2014
A={'ID' 'SP' 'MD' 'FI'
'1234' 'BBB-' 'Baa3' []
'1235' [] [] 'A-'
'1236' 'BB' 'Ba1' 'BB+'
'1237' 'A' 'A3' []}
B=cell2dataset(A)
B.ID=str2double(B.ID)
  2 comentarios
Matthew
Matthew el 23 de Abr. de 2014
Azzi / Andreas,
Thank you for your help.
I tried your code before and have tried it since you have sent it.
The following error message is produced:
Error using cell2dataset (line 127) NEWNAMES must be a nonempty string or a cell array of nonempty strings.
The 'ID' column is not a string which is causing the issue.
Andreas Justin
Andreas Justin el 23 de Abr. de 2014
could you show us the value of NEWNAMES when this error happens?
and the line of code you're using cell2dataset

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by