Write cell with struct to CSV

1 vue (au cours des 30 derniers jours)
rnd rnd
rnd rnd le 4 Août 2020
Commenté : Rik le 4 Août 2020
I have a cell of the form:
{1,1,"string", struct1}
{2,2,"string2",struct2}
.....
where struct1 may be: "string 1", value1
"string 2", value 2
I want to write the data to a csv file.
For now I am using fprintf, but no success with the struct data type.
fprintf(fid,'%g, %g, %s, %g\n',C{:,:})
From what I have I want to write to the CSV file something like this:
1,1,"string","struct 1 string1", struct 1 value1, "struct 1 string 2", struct 1 value 2, ... , etc
2,2,"string2","struct 2 string 1", struct 2 value 1, "struct 2 string 2", struct 2 value 2, ... , etc
...
So basicaly I want to include in the CSV also the field and the value for each structure, one by one on the same row.
Some help would by highly appreciated.
MATLAB R2020a
  1 commentaire
Rik
Rik le 4 Août 2020
As a first step you can use fieldnames and struct2cell to unwind the struct itself. Then you will have to do the relevant conversions for each field.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by