Can we change the size of cell inside the cell array?

7 visualizaciones (últimos 30 días)
Sushil Pokharel
Sushil Pokharel el 9 de Jun. de 2022
Editada: Voss el 12 de Jun. de 2022
Hi there,
Will it be possible to change the size of the cell inside the cell array? For instance, consider a cell array of size 3X6 and each cell contains 6x1 matrix. Now what I want is a cell array of 1x6 and each cell should contains 6x3 matrix. Any help will be greatly appreciated.

Respuesta aceptada

Voss
Voss el 9 de Jun. de 2022
Editada: Voss el 9 de Jun. de 2022
% a cell array of size 3X6 and each cell contains 6x1 matrix
C = cell(3,6);
for ii = 1:size(C,1)
for jj = 1:size(C,2)
C{ii,jj} = rand(6,1);
end
end
disp(C);
{6×1 double} {6×1 double} {6×1 double} {6×1 double} {6×1 double} {6×1 double} {6×1 double} {6×1 double} {6×1 double} {6×1 double} {6×1 double} {6×1 double} {6×1 double} {6×1 double} {6×1 double} {6×1 double} {6×1 double} {6×1 double}
[C{1,1} C{2,1} C{3,1}]
ans = 6×3
0.4479 0.8684 0.1091 0.6093 0.1725 0.5257 0.7553 0.3436 0.1281 0.9506 0.9163 0.5866 0.4100 0.2271 0.2420 0.0169 0.0942 0.0153
% what I want is a cell array of 1x6 and each cell should contains 6x3 matrix
C_new = cell(1,6);
for ii = 1:numel(C_new)
C_new{ii} = [C{:,ii}];
end
disp(C_new);
{6×3 double} {6×3 double} {6×3 double} {6×3 double} {6×3 double} {6×3 double}
C_new{1}
ans = 6×3
0.4479 0.8684 0.1091 0.6093 0.1725 0.5257 0.7553 0.3436 0.1281 0.9506 0.9163 0.5866 0.4100 0.2271 0.2420 0.0169 0.0942 0.0153
  2 comentarios
Sushil Pokharel
Sushil Pokharel el 9 de Jun. de 2022
@Voss, Thank you so much for your help. I really appreciate it and this is exactly what I want.
Voss
Voss el 9 de Jun. de 2022
Editada: Voss el 12 de Jun. de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by