Put vectors of different lengths into cells
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!