How to store all the results in a cell?

1 visualización (últimos 30 días)
M
M el 22 de Jul. de 2023
Comentada: M el 22 de Jul. de 2023
Suppose there is a cell "d" and its size 6*6
and I want to perfom a calculation on it and store all the results in "d11"
I tried the following but I got only the last index but I want all the results.
What I have to modify?
d11 = cell(6,6);
d = num2cell(rand(6));
for i = 6
for j= 6
d1 = [d{i,j};zeros(1,size(d{i,j},2))];
d11{i,j} = d1
end
end
d11 = 6×6 cell array
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {2×1 double}

Respuesta aceptada

Image Analyst
Image Analyst el 22 de Jul. de 2023
You didn't say what you expect, and the code is so wrong in so many ways that I can't figure out what you want. So I made this attempt.
d11 = cell(6,6);
d = num2cell(rand(6))
[rows, columns] = size(d11);
for col = 1 : columns
for row = 1 : rows
thisCellContents = [d{row, col}; zeros(rows, 1)];
d11{row, col} = thisCellContents;
end
end
celldisp(d11)
Is it what you want?
  1 comentario
M
M el 22 de Jul. de 2023
@Image Analyst, I got the error
i put
for i = 6
for j= 6
instead of
for i = 1: 6
for j= 1:6
I dont know how I didnt notice it!
Thanks

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by