Saving the content of a cell array

67 views (last 30 days)
Avik nayak
Avik nayak on 4 May 2019
Answered: Walter Roberson on 4 May 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 .

Answers (1)

Walter Roberson
Walter Roberson on 4 May 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

Categories

Find more on Cell Arrays in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!