Struct to N dimension matrix.
6 次查看(过去 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!