Converting .mat file in a txt

Mattia_Setti
Mattia_Setti Altair Community Member
edited July 2021 in Community Q&A

Hi,

I've received a .mat file but I do not have Matlab available. So I loaded it into Compose and saw its structure composition. Now I'm trying to convert it into an accessible .txt or .csv file to handle the data. Is it possible? Which commands should I use to extract the structures?

Thanks a lot!

Mattia

Best Answer

  • Lorenzo Moretti_20252
    Lorenzo Moretti_20252 New Altair Community Member
    edited July 2021 Answer ✓

    Ciao Mattia,

     

    after you load a mat file to Compose, you should see that the Variable Browser gets populated with the variables contained in the mat file.

    If inside this mat file there are also structs, you can access every filed of the structs with the "." operator.

    For example, if you have a struct called mystruct with a certain field called myfield, you can access it through:

     

    mystruct.myfield

     

    Supposing that this field contains a matrix, you can then save it to a csv file as follows:

     

    csvwrite('mycsvfile.csv', mystruct.myfield);

     

    Note that you can give the absolute path (instead of just the name) as the 1st argument of csvwrite function, if you want to save the csv file in a specific folder.

     

    Hope it helps,

     

    Lorenzo

Answers

  • Lorenzo Moretti_20252
    Lorenzo Moretti_20252 New Altair Community Member
    edited July 2021 Answer ✓

    Ciao Mattia,

     

    after you load a mat file to Compose, you should see that the Variable Browser gets populated with the variables contained in the mat file.

    If inside this mat file there are also structs, you can access every filed of the structs with the "." operator.

    For example, if you have a struct called mystruct with a certain field called myfield, you can access it through:

     

    mystruct.myfield

     

    Supposing that this field contains a matrix, you can then save it to a csv file as follows:

     

    csvwrite('mycsvfile.csv', mystruct.myfield);

     

    Note that you can give the absolute path (instead of just the name) as the 1st argument of csvwrite function, if you want to save the csv file in a specific folder.

     

    Hope it helps,

     

    Lorenzo

  • Mattia_Setti
    Mattia_Setti Altair Community Member
    edited July 2021

    Ciao,

    I missed the "." operator to navigate through the structure. With this, I could operate within the structure freely.

    Thanks for the support!

     

    Mattia