Adding column in cell array before converting to a matrix.
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Emily
el 7 de Ag. de 2024
Comentada: Stephen23
el 7 de Ag. de 2024
I have a cell array with 23 X 1 doubles. Within each cell double there are two columns with thousands of rows.
Each of the 23 cells is representative of a sample in a project.
I need to convert this cell array into a matrix with all the data, but the final matrix needs to have an identifer with the cell name from the previous array (ex. 1,2,etc). The screenshot is an example of what I'm looking for within the first cell of the array. How do I add a column with values to one cell in a cell array?
0 comentarios
Respuesta aceptada
Stephen23
el 7 de Ag. de 2024
Editada: Stephen23
el 7 de Ag. de 2024
Here are a couple of approaches. First lets create some fake data:
C = {randi(9,3,2),randi(9,2,2),randi(9,4,2)}
C{:}
Method one: CELLFUN and REPELEM:
X = cellfun(@height,C);
Y = 1:numel(X);
D = [vertcat(C{:}),repelem(Y(:),X,1)]
Method two: FOR-loop (modifies the original data):
for k = 1:numel(C)
C{k}(:,3) = k;
end
M = vertcat(C{:})
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays 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!