Saving a Structured Array (containing plot parameters) to a mat file
Hi, Im trying to save plot data by using a structured arra
ax=app.UIAxes;
ax.Children;
h1 = findall(ax, ‘type’, ‘line’); % Line objects
nlines=numel(h1);
Assign the desired plot parameters to a struct "S"
for i=1:nlines
thisLine=h1(i);
S(i).Xdata=thisLine.XData; S(i).Ydata=thisLine.YData;
S(i).Colour=thisLine.Color;
S(i).LineStyle=thisLine.LineStyle;
S(i).LineWidth=thisLine.LineWidth;
S(i).DName=thisLine.DisplayName;
end
Save to a .MAT file
try
[file,folder]=uiputfile({‘*.mat’,’Matlab Files’},’Save Data’,app.startfolder);
catch
[file,folder]=uiputfile({‘*.mat’,’Matlab Files’},’Save Data’,’C:’);
end
app.startfolder=folder;
savepath=fullfile(folder,file);
save(savepath,"-struct",’S’)
But I keep getting this error:
Error using save
The argument to -STRUCT must be the name of a scalar structure variable.
I have checked the class of S and the fieldnames contained within it:
fields = fieldnames(S)
class(S)
fields =
6×1 cell array
{‘Xdata’ }
{‘Ydata’ }
{‘Colour’ }
{‘LineStyle’}
{‘LineWidth’}
{‘DName’ }
ans =
‘struct’
Thanks for any helpHi, Im trying to save plot data by using a structured arra
ax=app.UIAxes;
ax.Children;
h1 = findall(ax, ‘type’, ‘line’); % Line objects
nlines=numel(h1);
Assign the desired plot parameters to a struct "S"
for i=1:nlines
thisLine=h1(i);
S(i).Xdata=thisLine.XData; S(i).Ydata=thisLine.YData;
S(i).Colour=thisLine.Color;
S(i).LineStyle=thisLine.LineStyle;
S(i).LineWidth=thisLine.LineWidth;
S(i).DName=thisLine.DisplayName;
end
Save to a .MAT file
try
[file,folder]=uiputfile({‘*.mat’,’Matlab Files’},’Save Data’,app.startfolder);
catch
[file,folder]=uiputfile({‘*.mat’,’Matlab Files’},’Save Data’,’C:’);
end
app.startfolder=folder;
savepath=fullfile(folder,file);
save(savepath,"-struct",’S’)
But I keep getting this error:
Error using save
The argument to -STRUCT must be the name of a scalar structure variable.
I have checked the class of S and the fieldnames contained within it:
fields = fieldnames(S)
class(S)
fields =
6×1 cell array
{‘Xdata’ }
{‘Ydata’ }
{‘Colour’ }
{‘LineStyle’}
{‘LineWidth’}
{‘DName’ }
ans =
‘struct’
Thanks for any help Hi, Im trying to save plot data by using a structured arra
ax=app.UIAxes;
ax.Children;
h1 = findall(ax, ‘type’, ‘line’); % Line objects
nlines=numel(h1);
Assign the desired plot parameters to a struct "S"
for i=1:nlines
thisLine=h1(i);
S(i).Xdata=thisLine.XData; S(i).Ydata=thisLine.YData;
S(i).Colour=thisLine.Color;
S(i).LineStyle=thisLine.LineStyle;
S(i).LineWidth=thisLine.LineWidth;
S(i).DName=thisLine.DisplayName;
end
Save to a .MAT file
try
[file,folder]=uiputfile({‘*.mat’,’Matlab Files’},’Save Data’,app.startfolder);
catch
[file,folder]=uiputfile({‘*.mat’,’Matlab Files’},’Save Data’,’C:’);
end
app.startfolder=folder;
savepath=fullfile(folder,file);
save(savepath,"-struct",’S’)
But I keep getting this error:
Error using save
The argument to -STRUCT must be the name of a scalar structure variable.
I have checked the class of S and the fieldnames contained within it:
fields = fieldnames(S)
class(S)
fields =
6×1 cell array
{‘Xdata’ }
{‘Ydata’ }
{‘Colour’ }
{‘LineStyle’}
{‘LineWidth’}
{‘DName’ }
ans =
‘struct’
Thanks for any help struct, mat, save MATLAB Answers — New Questions