Effacer les filtres
Effacer les filtres

Saving the content of a cell array

76 vues (au cours des 30 derniers jours)
Avik nayak
Avik nayak le 4 Mai 2019
Hi
I want to save all the contents of the cell array having mutliple elements but i dont want to save the cell array. Is there any way i can do it .
c = { 1,'abc', 22 , struct_A }
save(''filename.mat','c')
.Presently when i am saving it the .mat file contains the cell array but i want to save the contents of cell array as in a single .mat file not the cell array as a whole .This is a requirement i. Please help if possible .
  1 commentaire
madhan ravi
madhan ravi le 4 Mai 2019
Perhaps writecell() ?

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 4 Mai 2019
No, this is not possible. .mat files can only store variables. Those values such as 1 and 22 must be stored inside some variable.
Is it possible that what you were hoping for was that there would become a variable named 'abc' with value 1, and a variable named 'struct_A' with value 22 ? And where you had struct_A in c, it is really 'struct_A' ?
If so then that can be done.
If the order is as you show, value and then name of variable, then
vals = c(1:2:end);
fields = c(2:2:end);
cs = cell2struct(vals, fields, 2);
save('filename.mat', '-struct', 'cs');
This would lead to a variable 'abc' with value 1, and variable 'struct_A' with value 22

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by