How to store all the results in a cell?

1 次查看(过去 30 天)
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}

采纳的回答

Image Analyst
Image Analyst 2023-7-22
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 个评论
M
M 2023-7-22
@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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by