필터 지우기
필터 지우기

Copy axes to uiaxes

조회 수: 16 (최근 30일)
PL.R
PL.R 2021년 10월 19일
댓글: Adam Danz 2021년 10월 20일
Hello,
I would like to copy axes to uiaxes, but I cannot find any way to achieve this properly. This would be a reverse of this functionnality https://www.mathworks.com/matlabcentral/fileexchange/73103-copyuiaxes
The goal is to allow an user to plot its data using the usual MATLAB way of doing, then use the created axe in a MATLAB app, inside an uiaxes component.
% User plots its data using usual MATLAB way
ax = plot(time, data);
xtitle('My title'); xlabel('Time (s)'); ylabel('Data'); grid on; xlim(limits) % and stuff like this
% Plot is then "projected" inside uiaxes component through inputs arguments
my_app(ax)
Startup function inside the app should be something like : (pseudo-code)
function startupFcn(app, user_ax)
app.my_axes = user_ax;
end
I am really suprised there is no built-in constructor being able to achieve this.
I would like axes properties to be kept (like title, legend, grid, labels, xlim, ylim...) and if possible even functions callbacks the user might have deisgned previously. (this last point is not the most important, though)
Suprisingly, I neither found nothing on Mathworks forums.
Any ideas ?

채택된 답변

Adam Danz
Adam Danz 2021년 10월 19일
편집: Adam Danz 2021년 10월 19일
Use copyobj instead to copy the entire external axes to a uipanel in your app.
Demo:
% Simulate the app with a uifigure and uipanel
uifig = uifigure();
uipan = uipanel(uifig);
% Create external plot
fig = figure();
ax = axes(fig);
hold(ax,'on')
plot(ax, magic(5))
plot(ax, magic(6),'*')
% Copy axes to uipanel
newax = copyobj(ax, uipan)
  댓글 수: 2
PL.R
PL.R 2021년 10월 20일
Thank you very much !
It is exactly what I was trying to achieve, but using copyobj(ax, uiaxes), which did not work. Using copyobj(ax, uipanel) does exaclty the trick.
Adam Danz
Adam Danz 2021년 10월 20일
You could, of course, copy the axes to the uifigure but using a uipanel offers better control, especially in apps.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by