[R2017a] save nested structure with save, append files, load it and check some 'string' fields with strcmp
이전 댓글 표시
Hey guys,
I am working on a GUI that allows users to save the data, initially in a text file, inside a nested structure into a file .m
clc; clear;
s1(1).name = 'CaCO3.....';
s1(1).time = [0 1 2 3 4 5 6 7 8 9 10];
s1(1).mass = [0.9,0.9,0.8,0.7,0.7,0.5,0.4,0.4,0.4,0.,4];
s1(1).heat = [0 1 2 3 4 5 6 7 8 9 10];
s1(2).name = 'MgCO3.....';
s1(2).time = [0 2 4 6 8 10 12 14 16 18];
s1(2).mass = [1 1 1 1 1 1 1 1 1 1];
s1(2).heat = [9 9 9 9 9 9 9 9 9 9];
save('newstruct.mat', 's1');
disp('Contents of newstruct.mat:')
whos('-file', 'newstruct.mat')
clear('s1')
load('newstruct.mat')
A_cell = struct2cell(s1);
I want now to access all the field s1.name and check if among those there is a particular string, let's say 'CaCO3.....'.
Both:
[s1.name]
[A_cell{1,1,:}]
give me the following result: 'CaCO3.....MgCO3.....'
my questions are:
1) How can I put all results in an array? Or if I want to loop, how can I know the total length of the field .name?
2) If the name doesn't exist, how do I create a new substrcture s1(3)?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Debugging and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!