Info

此问题已关闭。 请重新打开它进行编辑或回答。

Hi, I am working on a project where I have to save 960 figures for future individual analysis. So I thought it best to save them in a 'cell' or 'struct' .mat file to load and plot when necessary. Please advice on how to re-plot from a .mat file.

1 次查看(过去 30 天)
x = rand(1,1000);
y = rand(1,1000);
z = rand(1,1000);
h = scatter3(x,y,z);
S = struct('fi',h);--------------------%Saving 'h' in a Struct
O{1,1}=h;------------------------------%Saving 'h' in a Cell
save('Struct.mat', 'S')
save('Cell.mat', 'O')
%Now after clearing everything, I am able to load the saved .mat files.
%How do I plot these into a figure.
%% The following is what gets saved in the .mat file. >> O{1,1}
ans =
Scatter with properties:
Marker: 'o'
MarkerEdgeColor: 'flat'
MarkerFaceColor: 'none'
SizeData: 36
LineWidth: 0.5000
XData: [1x1000 double]
YData: [1x1000 double]
ZData: [1x1000 double]
CData: [1x3 double]
Show all properties

回答(2 个)

Stephen23
Stephen23 2018-10-14
编辑:Stephen23 2018-10-14
Your idea is good, but MATLAB has a specific file format for saving and loading figures: the .fig file. It makes saving and loading figures easy: just like this:
saveas('file.fig',gcf) % all versions
savefig(gcf,'file.fig') % R2013b+
fgh = openfig('file.fig');
When you load it with openfig the figure will displayed (unless you select the 'invisible' option).
Read more:
  1 个评论
Hari Tejas Iyer
Hari Tejas Iyer 2018-10-14
Hi Stephan,
Thanks for the response.
In a loop this will generate 960 .fig files, I do not require to save so many. Instead I want to choose and plot from one .mat file - the cell 'O'.
O{10,60,16}
10 - saved properties. (*)
60 - instances of data.
16 - data sources.
(*) I want to record the .fig files in the cell 'O', as one of the 10 properties of my data (others are fit, RSq, etc . . .).

Hari Tejas Iyer
Hari Tejas Iyer 2018-10-15
Hello,
A temporary solution could be to define a function, which calls on the plot data saved in the cell.
function fitplot
prompt1='Input .mat file?';
prompt2='Shot number?';
prompt3='Spectrometer number?';
load(input(prompt1,'s'));
Shot=input(prompt2);
Spec=input(prompt3);
x = O{5,Shot,Spec};
y = O{6,Shot,Spec};
fitt = O{2,Shot,Spec};
data =['Shot-',num2str(Shot),', Spectrometer-',num2str(Spec)];
figure('name', data);
plot(fitt,x,y);
xlabel('Wavelength(nm)');
ylabel('Intensity(a.u)');
end

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by