Struct to N dimension matrix.
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi,
I am new to MATLAB and currently am dealing with a struct with three columns (Area,Centroid and BoundingBox).
There are 14 instances in total. The Centroid column consists of data which are comma seperated like [102.92,429.33]. I have to convert this column in to a 14x2 matrix.
I tried
matr = {comp.Centroid}';
but it returned a 14x1 cell.
Kindly help me regarding the issue.
Thanks
댓글 수: 0
채택된 답변
Ameer Hamza
2020년 10월 8일
편집: Ameer Hamza
2020년 10월 8일
vertcat(comp.Centroid)
% or
reshape([comp.Centroid], 2, []).'
댓글 수: 2
Ameer Hamza
2020년 10월 8일
I am glad to be of help! MATLAB is well-known for its vectorized operations, and loops can be avoided in most situations. For example, even with your line of code, you can get the same output by using cell2mat
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!