필터 지우기
필터 지우기

Matlab App Desinger: How to update a figure with button

조회 수: 30 (최근 30일)
Renan Deuter
Renan Deuter 2021년 2월 5일
답변: Mario Malic 2021년 2월 5일
Hello,
I want to create multiple plots in an app and later update the plots when new data is added.
In one step the user can add data (in this case a trajectory) and plot a preview. Later on the user can add another data (a single coordinate inside the trajectory) and I want this new point to be plotted inside the wirst figure window. Right now I'm having the issue that App Desinger always opens a new window.
Here's a simplified version of my code so far:
app.counter = 0;
function FirstButtonPushed(app, event)
% check if user selected a file yet
position = importfile1(filename); % imports table with Lat and Lon
% plot the preview
fig_trajectory = uifigure('Name', 'Trajectory');
hold on;
plot(position.Longitude, position.Latitude);
% check if user has skipped this step and already added the new additional data
if app.counter >= 1
plot(app.vpos(:,2), app.vpos(:,1), '*')
end
end
function SecondButtonPushed(app, event)
app.pos = [48.0000 11.0000; 48.0001 11.000];
app.counter = app.counter +1;
% call previous plot
% add data
plot(app.pos(:,2), app.pos(:,1), '*')
How can I tell Matlab to update the figure?
Thanks in Regards!

채택된 답변

Mario Malic
Mario Malic 2021년 2월 5일
Hi,
the best way to add/modify the plot data is by XData, YData, ZData, or XDataSource, ... properties. Probably, by changing their properties, callback to automatically update the plot will be executed and there won't be need for refresh button.
In AppDesigner, you need to provide the handle to the UIAxes component you're plotting on, then it won't open the new figure.
x = 1;
y = 1;
h = plot(app.UIAxes, x, y); % saving the handle h of the line object,
If you want to change the data (this is useful if you have a lot of points in your graph), here's an example
xNew = [x, 2];
yNew = [y, 3];
set(h, 'XData', xNew, 'YData', yNew);
if not, then you can use the plot function like shown above.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by