Turn a cellarray into a single array.
Mostrar comentarios más antiguos
I have a cell array, sig, with varying lengths of data in each cell. For example (on a simplified scale)
sig = [{1}; {[2 3 4]}; {[5 6]}];
n = cellfun(@length,sig);
n is the length of each cell. I want to plot the data in each cell according to their cell index. For this example the answer would be
x = [1, 2,2,2, 3,3]; % indices of each cell
y = [1, 2,3,4, 5,6]; % value of each array element
scatter(x,y,'o');
So the question is, how can I acquire x, y programmatically?
Respuesta aceptada
Más respuestas (1)
Guillaume
el 24 de Mzo. de 2015
sig = {[1]; [2 3 4]; [5 6]}; %note that your sig is a cell column
%because sig is a column it has to be transposed in the two instructions below:
X = cell2mat(arrayfun(@(c, p) p*ones(1, numel(c{1})), sig', 1:numel(sig), 'UniformOutput', false))
Y = cell2mat(sig')
1 comentario
John Petersen
el 24 de Mzo. de 2015
Categorías
Más información sobre Data Types 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!