Can I save UIAxes plot in anyway?
古いコメントを表示
Hi!
How do I save a plot I made with UIAxes, ie. NOT with figure - I tried print but it didn't work and I don't understand why. Is there ANYWAY to save a UIAxes plot?
My question is about Appdesigner.
3 件のコメント
Lydin Camilleri
2018 年 4 月 5 日
any answer to this pleasE?
shahram maghami
2019 年 3 月 24 日
no solution yet ?
I've same problem.
farzad
2020 年 4 月 2 日
did you manage finally ? which one worked for you ?
採用された回答
その他の回答 (1 件)
Will Grant
2019 年 5 月 2 日
編集済み: Will Grant
2019 年 5 月 2 日
Inspired by Adam's answer, here is a function you can call directly with slightly enhanced functionality.
Note the addition of calling copyobj() with the title and label objects, and removing them from the set() when transfering property values. Adam's original code re-parents the title and label objects to the new axes. The label objects are still located under the original axes, but their respective label.Parent property is set to axTo, a fairly useless situation.
function myCopyObj(axFrom, axTo)
% Custom version of copyobj() which works to copy a UIAxes object to
% an old-school axes object.
% Copy children (lines).
copyobj(axFrom.Children, axTo);
% Copy titles and labels.
copyobj([axFrom.Title axFrom.XLabel axFrom.YLabel], axTo)
% Transfer other properties.
uiAxParams = get(axFrom);
uiAxParamNames = fieldnames(uiAxParams);
% Get list of editable params in new axis
editableParams = fieldnames(set(axTo));
% Remove the UIAxes params that aren't editable in the new axes (add others you don't want)
badFields = uiAxParamNames(~ismember(uiAxParamNames, editableParams));
badFields = [badFields; 'Parent'; 'Children'; 'XAxis'; 'YAxis'; 'ZAxis'; ...
'Position'; 'OuterPosition'; 'XLabel'; 'YLabel'; 'ZLabel'; 'Title'];
uiAxGoodParams = rmfield(uiAxParams,badFields);
% set editable params on new axes
set(axTo, uiAxGoodParams)
end
To use:
% Define figure and axes to specifications.
f = figure('Visible', false);
axNew = axes(f);
% Copy.
myCopyObj(origUIAxesHandle, axNew);
% Print!
print(f, filePath);
delete(f);
3 件のコメント
Nice work!
Namwon Kim
2019 年 8 月 20 日
編集済み: Namwon Kim
2019 年 8 月 20 日
Thanks for your answer, and the code works very well.
Adam Danz
2019 年 8 月 20 日
I would add on small feature at the top of the function. If the "axTo" is not provided, it should be created within the function. That saves the user from creating the axes if the axes is just a simple, standard axes.
This would go at the top of the function.
% Generate new axes if 2nd input is missing or empty.
if nargin < 2 || isempty(axTo)
fh = figure();
axTo = axes(fh);
end
カテゴリ
ヘルプ センター および File Exchange で Develop Apps Programmatically についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!