Saving the content of a cell array

71 次查看(过去 30 天)
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 个)

Walter Roberson
Walter Roberson 2019-5-4
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

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by