Matlab saying that cell is empty when it is not?

2 次查看(过去 30 天)
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!

回答(1 个)

Alex Mcaulley
Alex Mcaulley 2019-4-22
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

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by