Converting cell array to matrix
조회 수: 85 (최근 30일)
이전 댓글 표시
Hi,
I have a 1x650 cell array (centroid1) which contains two values, an x and y coordinate in a (1,2) matrix. How do I convert this cell array into a (:,2) matrix containing the relevant coordinates in each row?
Below is my attempt, but this converts the cell array wih just 1 row.
coord = cell2mat(centroid1)
Thanks
댓글 수: 0
채택된 답변
Ameer Hamza
2020년 12월 3일
편집: Ameer Hamza
2020년 12월 3일
Use vertcat()
coord = vertcat(centroid1{:})
following should also work
coord = cell2mat(centroid1.')
추가 답변 (1개)
Fangjun Jiang
2020년 12월 3일
>> a={[1 2],[3 4]}
a =
1×2 cell array
{1×2 double} {1×2 double}
>> cell2mat(a)
ans =
1 2 3 4
>> cell2mat(a')
ans =
1 2
3 4
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!