Filter löschen
Filter löschen

Converting cell array to matrix

85 Ansichten (letzte 30 Tage)
Mark Coughlin
Mark Coughlin am 3 Dez. 2020
Kommentiert: Mark Coughlin am 3 Dez. 2020
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

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 3 Dez. 2020
Bearbeitet: Ameer Hamza am 3 Dez. 2020
Use vertcat()
coord = vertcat(centroid1{:})
following should also work
coord = cell2mat(centroid1.')

Weitere Antworten (1)

Fangjun Jiang
Fangjun Jiang am 3 Dez. 2020
>> 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

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by