Filter löschen
Filter löschen

How to store all the results in a cell?

1 Ansicht (letzte 30 Tage)
M
M am 22 Jul. 2023
Kommentiert: M am 22 Jul. 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}

Akzeptierte Antwort

Image Analyst
Image Analyst am 22 Jul. 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 Kommentar
M
M am 22 Jul. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by