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
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Animation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!