Converting cell array to matrix

143 ビュー (過去 30 日間)
Mark Coughlin
Mark Coughlin 2020 年 12 月 3 日
コメント済み: Mark Coughlin 2020 年 12 月 3 日
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 件のコメント
Mark Coughlin
Mark Coughlin 2020 年 12 月 3 日
Brilliant! Thank you

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by