Bar3 crahes by plotting a cell array in a loop
Show older comments
Hi,
I have a M, which is a cell Array M, which is 1×1 cell array of {1×292 cell}. Each of the 292 consits again of cells different sizes
. M{1}=ans
1×292 cell array
Columns 1 through ...292
{1×288 cell} {1×288 cell} {1×287 cell} ...{1x260}.
Each of these cells consits of doubles with different number of rows but fixes amount of columns(15).
m{1}{1}= ans
1×288 cell array
Columns 1 through ...288
{34×15 double} {36×15 double} {37×15 double}.. {95x15}.
I would like to plot M with bar3. My code:
figure();
Az=(1:1:15);
for t1=1:292
for t2=1:length( M{1}{t1})
bar3(Az,(cell2mat(M{1}{t1}(t2))');
hold on;
end
end
After ~2h matlab has crahesd (killed)
Is there another way to plot it?
Accepted Answer
More Answers (1)
CSCh
on 5 May 2023
0 votes
3 Comments
CSCh
on 8 May 2023
Nathan Hardenberg
on 8 May 2023
I would use the same loop and pad with NaNs:
B = [N{t1}{1}; nan(maxRows-rowA, colum)];
Then store all B matrecies in one 3 dimensional matrix
C = nan(maxRows, colum, 0) % define outside of loop
C(1:maxRows, 1:colum, end+1) = B; % inside of loop
Then just take the mean in the third axis and omit the NaN values.
mean(C,3,"omitnan")
This is not the optimal solution, but should be enough for one calculation.
It is really weird why the data is stored in the way it is when it is useful to take the mean of all values. Just wondering.
CSCh
on 9 May 2023
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
