Saving a structure with the title of a plot as name

4 ビュー (過去 30 日間)
Claudius Simon Appel
Claudius Simon Appel 2020 年 6 月 11 日
回答済み: Claudius Simon Appel 2020 年 6 月 12 日
Hello,
I am currently trying to get get a function that will both save a newly created figure as a .fig-file with it's title being the file name. That works so far.
However, aside from that, the structure that includes all data used for creating the figure should also be saved under the same name. With this second part, I have troubles.
Is there a way to achieve this? It would surprise me if there isn't a way to do this.
function Savefigfun(LPData)
% Savefig saves the newly created figure as a .fig-file named after the
% title of the figure. The saved figure is still editable afterwards.
CurrentFigureTitle=get(gca,'title');
if isempty(CurrentFigureTitle.String)
warning('Error occured.\nCan''t save a figure without title. Please set title before calling [Savefigfun]','class(n)')
warning off
else
savefig(CurrentFigureTitle.String);
save(CurrentFigureTitle.String,"LPData")
end
% created by Claudius Appel.
% https://de.mathworks.com/matlabcentral/profile/authors/16470428-claudius-simon-appel
end
Thank you.
Have a great day & stay safe
Claudius Appel
  6 件のコメント
Geoff Hayes
Geoff Hayes 2020 年 6 月 11 日
Claudius - it sounds like CurrentFigureTitle.String is a cell array and so when you access the first element with {1}, you get the string that you expect. Alternatively, you could probably do
save(char(CurrentFigureTitle.String),"LPData")
to get the same result.
Claudius Simon Appel
Claudius Simon Appel 2020 年 6 月 11 日
@Geoff Hayes
Oh, I didn't know that.
I might see which one of the two is more prone to errors.
Every day I learn something new about this program. It is awesome :)
Thank you.

サインインしてコメントする。

採用された回答

Claudius Simon Appel
Claudius Simon Appel 2020 年 6 月 12 日
Thank you Geoff Hayes for answering the question and solving the problem.
Link to his comment:
https://www.mathworks.com/matlabcentral/answers/546476-saving-a-structure-with-the-title-of-a-plot-as-name#comment_893957

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by