Trying to delete the previous data/line from a next button using matlab Gui

조회 수: 8(최근 30일)
Hello everyone,
i have a little problem. I was able to code a "Next button" using app designer that have as aim to draw lines. I had the data coming from excel. I am able to draw each line by clicking on the next button. The only problem is that the previous data/line is not deleted. So instead of having one line, i will have 2 or more depending on how many times i click on the next button.
To illustrate it more, you can see the attached document. I am expecting to have just one LINE/BAND
the Next button code is below
uiconfirm(app.UIFigure,'Are You sure?','Confirm Close',...
app.exp_counter = app.exp_counter + 1;
v_or_h = app.v_or_h_array(app.exp_counter);
app.v_thick1 = app.v_thickness_1(app.exp_counter);
app.v_thick2 = app.v_thickness_2(app.exp_counter);
app.h_thick1 = app.h_thickness_1(app.exp_counter);
app.h_thick2 = app.h_thickness_2(app.exp_counter);
%Vertical line
if v_or_h == 0
app.region1 = patch(app.UIAxes, ...
[app.v_thick1 app.v_thick2 app.v_thick2 app.v_thick1], ...
[-10 -10 10 10],'r', ...
'LineWidth',0.01, ...
%Horizontal line
elseif v_or_h == 1
app.region1 = patch(app.UIAxes,[-10 10 10 -10], ...
[app.h_thick1 app.h_thick1 app.h_thick2 app.h_thick2], ...
'LineWidth',0.01, ...
  댓글 수: 1
Franck paulin Ludovig pehn Mayo
Franck paulin Ludovig pehn Mayo 2021년 10월 20일
@Geoff Hayes and this is the last code.
function UIFigureWindowButtonMotion(app, event)
% Determine if mouse is within uiaxes
cp = app.UIFigure.CurrentPoint;
isInAxes = cp(1) >= app.UIAxes.Position(1) && ...
cp(1) <= sum(app.UIAxes.Position([1,3])) && ...
cp(2) >= app.UIAxes.Position(2) && ...
cp(2) <= sum(app.UIAxes.Position([2,4]));
if isInAxes
set(app.CurrentPositionEditField, 'Value',...
sprintf('%.2f, %.2f', app.UIAxes.CurrentPoint(1,1:2)))
set(app.CurrentPositionEditField, 'Value', '')

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

채택된 답변

Geoff Hayes
Geoff Hayes 2021년 10월 18일
@Franck paulin Ludovig pehn Mayo - If you only want one patch object to appear, then you will need to delete the old one before creating the new one since you overwrite the "old" patch handle with the new one:
app.region1 = patch(app.UIAxes, ...
You would need a line of code like
if ishandle(app.region1)
called before you draw the new patch. Note that I'm assuming that the app object has an attribute named region1. If non such attribute exists, then you will need to handle that case.
  댓글 수: 11
Franck paulin Ludovig pehn Mayo
Franck paulin Ludovig pehn Mayo 2021년 10월 21일
@Geoff Hayes Thank you very much. It has been solved .I deeply appreciate that. Blessings.

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

추가 답변(0개)


Community Treasure Hunt

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

Start Hunting!

Translated by