Adding a Graph into a uipanel GUI

조회 수: 57 (최근 30일)
Erick Magana
Erick Magana 2019년 12월 6일
댓글: Erick Magana 2019년 12월 6일
I am trying to add a graph into a uipanel that I have on my matlab GUI. I have a pushbotton that intakes information from empty text boxes and then after I use the push botton it makes a graph. I want to have this graph appear on my uipanel rather than a second window, is that possible or would I have to use a axis? I was planning on having adding a map into that panel as well, but later on.

답변 (1개)

Thomas Satterly
Thomas Satterly 2019년 12월 6일
You need to create an axis object where the data will be plotted and pass this axis as the first argument to your plot function.
% Create a figure
fh = figure();
% Create a panel to hold the plot axis
axisPanel = uipanel(fh, 'Position', [0 0 0.5 1], 'BackgroundColor', [1 1 1]);
% Create a new axis on the panel
leftAxis = axes(axisPanel, 'Position', [0.1 0.1 0.8 0.8]);
% Create a different panel to hold the button and a second axis
buttonPanel = uipanel(fh, 'Position', [0.5 0 0.5 1], 'BackgroundColor', [0.7 0.7 0.7]);
% Create an axis on the right panel
rightAxis = axes(buttonPanel, 'Position', [0.1 .3 0.8 0.6]);
% Create pushbuttons to plot data
leftPlotButton = uicontrol(buttonPanel, 'Style', 'pushbutton', ...
'String', 'Plot Left', 'Units', 'normalized', 'Position', [0.1 0 0.3 0.1], ...
'Callback', @(src, event) buttonPressCallback(leftAxis));
rightPlotButton = uicontrol(buttonPanel, 'Style', 'pushbutton', ...
'String', 'Plot Right', 'Units', 'normalized', 'Position', [0.6 0 0.3 0.1], ...
'Callback', @(src, event) buttonPressCallback(rightAxis));
function buttonPressCallback(thisAxis)
% Plot on the specified axis
plot(thisAxis, rand(1, 10), rand(1, 10), 'r.');
end
It's also possible to create the graphics object itself (e.g. 'matlab.graphics.chart.primitive.Line') and set the 'Parent' property to the axis you want it to appear on, rather than use a 'plot'-style command
  댓글 수: 1
Erick Magana
Erick Magana 2019년 12월 6일
Sorry I should have been a bit more specific, I am getting user data from a text box then after have then push the oushbutton. That pushbutton will do some calculations and use the data from the calculation to display the plot. Would it require me to have mulitple pushbuttons to do this, or is one enough?
These are all different functions within my actual code. The math and plotting code is all done under the pushbutton function.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by