array of structures to cell array via comma-separated list
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 28 Jan. 2013
Bearbeitet: Azzi Abdelmalek
am 28 Jan. 2013
for k=1:size(data,2)
out{k}=data(k)
end
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!