converting cell array of strings (dates) to matrix

2 visualizaciones (últimos 30 días)
tombola
tombola el 24 de Nov. de 2011
Hi, I get a cell array of strings by calling a sqlserver stored procedure. The strings are all dates "dd/mnm/yyyy" which I want to keep in string format.
Cell2mat creates (for an array of 100 cells) a 100x10 matrix, not the 100x1 I would like.
As my strings are all the same length, is there an easy way to convert to a matrix please?
Thanks a lot,
Tom

Respuesta aceptada

Andrei Caragea
Andrei Caragea el 24 de Nov. de 2011
Hey tombola.
The problem is that matlab views a string as a row of ascii values. For example, if you have a date like '01/01/2000', this is viewed as [48 49 47 48 49 47 50 48 48 48]. This is precisely why you get a 100*10 matrix. The cell format views the string '01/01/2000' as a single "object", so if you try size(cell) it will give [100 1]. But the string format is different. If you need to work with the string form, convert inside of the specific function you are using, i.e. instead of having C as the cell and M=cell2mat(C), try f(cell2mat(C(i)) where f is your function and i the current index.
BTW, if you want to see this in action, just try '01/01/2000'+1-1 in the command window.
  1 comentario
Walter Roberson
Walter Roberson el 24 de Nov. de 2011
f(cell2mat(C(i))) would be f(C{i}) unless you have a cell array of cell arrays.

Iniciar sesión para comentar.

Más respuestas (1)

Titus Edelhofer
Titus Edelhofer el 24 de Nov. de 2011
Hi,
hmm, I don't understand: you have a cell array of strings (i.e., you have some 100x1 cell array). What exactly is the output you expect?
Titus

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by