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

采纳的回答

Ameer Hamza
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
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

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by