Effacer les filtres
Effacer les filtres

Loading a .mat file as a cell and without changing its size

19 vues (au cours des 30 derniers jours)
SelDen le 11 Mar 2022
Modifié(e) : Stephen23 le 11 Mar 2022
I have a large cell array in a .mat file which I want to load into the code. But when I write
data = load('temp.dat');
data is a 1x1 struct. How can I save the data as a cell array (not as 1x1 cell) ?
  1 commentaire
Stephen23 le 11 Mar 2022
Modifié(e) : Stephen23 le 11 Mar 2022
The robust approach:
S = load('temp.dat');
data = S.nameOfFieldInMatFile
And in the special case that there is only one variable in the file and you do not know its name:
C = struct2cell(load('temp.dat'));
data = C{1};
If you are interested in writing robust code it is best to avoid LOADing directly into the workspace.

Connectez-vous pour commenter.

Réponses (2)

Sugar Daddy
Sugar Daddy le 11 Mar 2022
Look son, here is an easy way
just load it, no need to assign it to specific variable

Star Strider
Star Strider le 11 Mar 2022
It depends on what is in ‘temp.dat’.
If it only contains the cell array, just load it into your workspace. If it contains other vairables that are not desired, specify the variable to load:
It will then exist in your workspace with that variable name.


En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by