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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!