Matlab App Desinger: How to update a figure with button
24 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!