Put vectors of different lengths into cells

1 次查看(过去 30 天)
I have three vectors. They all have 466 elements (466x1 vectors).
Vector1= the value 173 on 224 rows followed by 242 zeros
Vector2= zeros on 224 rows followed by the value 174 on 136 rows followed by 106 zeros
Vector 3= zeros on 360 rows and the value 178 on 106 rows
I put these vectors in IDmatrix=[Vector1 Vector2 Vector3]
Each of the elements in the vectors represent a date in (tripStats.stop_time_string) e.g. '"2010-07-03 08:51:37"' that is specific for each row and value (173,174 and 178)
What I want is to put all the dates in a single cell array. I have tried the following:
n=3;
M=cell(n,1);
ID=[173 174 178];
for o=1:n
for l=1:466
if IDmatrix(l,o)==0
break
elseif IDmatrix(l,o)==ID(o)
StopDatev=[StopDatev ;datevec(tripStats.stop_time_string(l,:))];
end
end
M{o}=StopDatev
StopDatev=[];
end
The result is
{224×6 double}
{ 0×0 double}
{ 0×0 double}
what I want to accomplish is
{224×6 double}
{ 136×6 double}
{ 106×6 double}

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by