How to prevent automatic cell array dimension assignment

2 views (last 30 days)
I want to generate a 3D cell array called timeData so that timeData(:,:,a) for some integer a is an nx1 matrix of data, and the number of rows n varies with the value of a in a 1:1 correspondence. To do this, I am generating a 2D array of data called data that is nx1. This assignment statement takes place within a for loop as follows:
for m=1:numIter
data = [1.1;2.3;5.5;4.4]; % This is one example of what data could be. Its number of columns, n, changes each
% iteration, as do its contents.
A = [1,2,3,4,5];
sizeA = size(A);
for k=1:sizeA(2)
B = size(data);
timeData(1:B(1),1,m) = num2cell(data);
This code does put all contents of data in the appropriate locations within timeData as I want. However, it also adds
{0x0 double }
rows to all 2D arrays of
for any a whose corresponding number of rows n was not the largest number of rows. Thus, there are many of these 2D arrays that have 10s to a couple hundred 0 valued rows that I don't want. How can I modify my assignment statement to fix this?
PS: I understand the way I am going about dynamically changing the size of timeData is considered bad practice. I'm not concerned with this since all that matters to me is that the code works.

Answers (0)


Find more on Structures 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!