ho can i convert a structure to a matrix?

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 23 Jul. 2015

28 Stimmen

cell2mat(struct2cell(YourStructure))

3 Kommentare

Walter Roberson
Walter Roberson am 30 Mai 2019
One of the toolboxes also has a little-documented struct2array() function,but I am not sure which toolbox.
See also https://www.mathworks.com/matlabcentral/fileexchange/54766-struct2mat-s which creates columns from structures, padding if needed.
Jacqueline Kelly
Jacqueline Kelly am 25 Sep. 2020
What if the cells aren't of the same data type? I have some strings and some numbers
Walter Roberson
Walter Roberson am 25 Sep. 2020
struct and cell are different datatypes; you need to be clear as to which you are working with for this purpose.
If you have a mix of strings and numbers, then what is your hope as to the datatype of the final matrix ? You can only combine strings and numbers in a single object if it is one of the composite datatypes such as struct, cell, or table.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

muhammed boztoprak
muhammed boztoprak am 30 Mai 2019

0 Stimmen

Really great answer!!! Thank you very much.

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by