In Matlab, at the end of three different for loops (for a=1:240,b=1:5 and c=1:3), I generate a {1,3} cell array where each cell contains a (1,5) array that reports only the last result of the 240 iterations. How can I generate, apart of this cell array, a (240,5,3) 3d array that stores the result of each iteration? Or, equivalently, a cell array that stores again the information and then convert it into a (240,5,3) 3d array?
How to store results created into a cell array during a multiple for loop into a 3d array? In Matlab
Asked
Active
Viewed 474 times
-1
-
Please post some example data (input and worked output). Also read this for how to index cell arrays: http://stackoverflow.com/a/25621199/1011724 – Dan May 27 '15 at 11:31
-
Yes you're rigth. Suppose I have: a=240; b=5; c=3; A {c}= cell (1,b) for i=1:a for j=1:b for k=1:c A{c}(b)= %assignment end end end where %assignment is a series of operation through a,b,c. Now, at the end of this loop I obtain only A{c}(b), whereas I would like to obtain also a A (a,b,c) with the partial result of every single iteration on a,b,c. – Giovanni Rinaldi May 27 '15 at 12:20
-
Please put the code from your comment in your actual question, it's too hard to read in a commen – Dan May 27 '15 at 18:01
-
This question is not clear. Why are only the last results stored? Why a {1,3} cell? What is exactly stored, a scalar? If so the answer becomes very simple, but the question is still very complex and probably won't help anyone else. – NoDataDumpNoContribution Jul 21 '15 at 14:04
1 Answers
0
The code would be along the lines of:
%// Size of the problem
Na = 240;
Nb = 5;
Nc = 3;
%// Allocate empty cell array
result = cell(Na, Nb, Nc);
%// Loop
for a = 1:Na
for b = 1:Nb
for c = 1:Nc
%// Here is the code for computing the
%// result x of the last iteration.
result{a,b,c} = x;
end;
end;
end;