convert struct of cell in a matrix of cell

 Risposta accettata

Guillaume
Guillaume il 27 Apr 2017
Modificato: Guillaume il 28 Apr 2017
Are you looking for
{L1.l} %for row vector of cells
or something more complex?

4 Commenti

elisa ewin
elisa ewin il 27 Apr 2017
Modificato: elisa ewin il 27 Apr 2017
vertcat don't run
'Error using vertcat
Dimensions of matrices being concatenated are not
consistent'
I want something more complex: I want that the struct became a matrix that have all the values in the field l; use {L1.l} gives a vector but I want have a matrix of cells like this:
A={'1' '142' '174' '168' '133' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '';'1' '142' '1' '133' '154' '167' '174' '142' '1' '131' '142' '1' '142' '' '' '' '' '' '' '' '' '';'174' '142' '1' '167' '1' '131' '142' '1' '131' '1' '131' '1' '142' '176' '150' '1' '' '' '' '' '' '';'174' '1' '137' '142' '133' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''; continue with all the values in the struct}
I hope it's clear
I shouldn't have edited my post to add the vertcat. Of course it wouldn't work.
However, it would have produced the exact result you wanted if all the cell arrays had the same number of columns. So the key to do what you want is to make all these cell arrays the same size before vertically concatenating them (assuming that's acceptable):
maxcols = max(arrayfun(@(l1) size(l1.l, 2), L1));
resizedcells = cellfun(@(c) [c, repmat({''}, size(c, 1), maxcols - size(c, 2))], {L1.l}, 'UniformOutput', false);
concatenatedcells = vertcat(resizedcells{:})
Why is this data not stored in a cell array in the first place? There is only one field in the structure, which totally defeats the purpose of using a structure.
If I have semanticTrajCluster.cluster.locID (attached), how can I make the same thing?

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by