array of structures to cell array via comma-separated list
Mostrar comentarios más antiguos
Suppose I have the following array of structs:
data(1).f1 = 1;
data(2).f1 = 2;
data(1).f2 = 'foo';
data(2).f2 = 'bar';
And I want to put each struct into one cell of a two-element cell array:
struct_as_cell = arrayfun(@(x) x, data, 'UniformOutput', false);
Is there any easier syntax to do this? I would have hoped that data(:) would generate a comma-separated list of structs so that I could do the following, just as I could if data was a cell array, but it doesn't seem to work:
struct_as_cell = {data(:)};
Cheers
4 comentarios
Azzi Abdelmalek
el 28 de En. de 2013
What is the problem with the syntax?
Eric Sampson
el 28 de En. de 2013
Cedric
el 28 de En. de 2013
Ah! I just learned something from Azzi's answer with num2cell().
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!