Creating a table from different sized vectors
이전 댓글 표시
I have a number of vectors (x1,y1,x2,y2, etc) with different lengts and I want to extract them to a .csv containing all these. Specifically,
- 1st column = x1 (289 rows)
- 2nd column = y1 (289 rows)
- 3rd column = x2 (300 rows)
- 4th column = y2 (300 rows)
I try to use the horzcat but it does not work due to different size. Any ideas or solutions?
댓글 수: 1
Stephen23
2015년 12월 17일
Rather than storing these in numbered variables these vectors should really be stored in a cell array. Then the task becomes a trivial loop with indexing to allocate the vectors into a proallcoated array.
Numbered variables are invariably a bad idea:
채택된 답변
추가 답변 (3개)
the cyclist
2015년 12월 17일
Depends on what you want to appear in the "empty" spot. You could use NaN. Then
M = [[x1; nan], [y1; nan], x2, y2]
and then export the matrix M.
the cyclist
2015년 12월 17일
One possibility is to store them in a cell array first, in which case empty will be empty.
M = cell(300,4);
M(1:299,1) = num2cell(x1);
M(1:299,2) = num2cell(y1);
M(:,3) = num2cell(x2);
M(:,4) = num2cell(y2);
Image Analyst
2015년 12월 17일
0 개 추천
I'd just use fprintf() and write it out manually.
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!