Azzera filtri
Azzera filtri

Saving the content of a cell array

76 visualizzazioni (ultimi 30 giorni)
Avik nayak
Avik nayak il 4 Mag 2019
Risposto: Walter Roberson il 4 Mag 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 .

Risposte (1)

Walter Roberson
Walter Roberson il 4 Mag 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

Categorie

Scopri di più su Cell Arrays in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by