Matlab saying that cell is empty when it is not?

1 view (last 30 days)
I have a 2x1460 cell. I'm trying to pull out the data from the matrixes, which are each 1x4, in the second row of cells.
for i = 1460;
hours{i} = U{2,i}
hrs(i) = hours{i}(4);
end
% U is my 2x1460 cell.
When I run the code matlab returns:
hours =
1×1460 cell array
Columns 1 through 6
{0×0 double} {0×0 double} . . .Columns 1456 through 1460
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {1×4 double}
where that last cell is correct.
This same code has worked before and I'm not sure what is going wrong here in particular. Any help is greatly appreciated!

Answers (1)

Alex Mcaulley
Alex Mcaulley on 22 Apr 2019
Your loop is not a loop in fact (it is only running for i = 1460, the last cell). Then you need:
for i = 1:1460;
hours{i} = U{2,i}
hrs(i) = hours{i}(4);
end

Categories

Find more on Resizing and Reshaping Matrices 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!