Trying to delete the previous data/line from a next button using matlab Gui
Afficher commentaires plus anciens
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',...
'CloseFcn',@(src,event)mycallback(app,src,event));
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', ...
'FaceAlpha',1,...
'LineWidth',0.01, ...
'LineStyle','-','tag','region1');
%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], ...
'r','FaceAlpha',1,...
'LineWidth',0.01, ...
'LineStyle','-','tag','region1');
end
3 commentaires
Franck paulin Ludovig pehn Mayo
le 20 Oct 2021
Walter Roberson
le 13 Oct 2023
In the code, app.UIFigure is the property name inside app that has been given to the handle of a uifigure object, and app.UIAxes is the property name inside app that has been given to the handle of a uiaxes object (that is presumably inside UIFigure)
Each UIFigure has a property which records CurrentPoint (current point is recorded independently for each different figure). The units for the position defaults to pixels . This code assumes that whatever units is being used for the uifigure, the same units are being used for the axes.
CurrentPoint is in the order x and then y.
Each UIAxes has a property Position which records the location of the axes. The units for the position defaults to pixels. It is a vector which has the order bottom-left x, bottom-left y, width, height . So sum(app.UIAxes.Position([1,3])) is extracting the x of the bottom left and adding the width to determine where the right hand side is, and sum(app.UIAxes.Position([2,4])) is calculating where the top is. The code is therefore determining whether the current x position is within the left and right limits of the axes, and the current y position is within the bottom and top limits of the axes.
The code could be more robust. It could, for example, look at the figure CurrentAxes property instead of assuming a particular axes. It could avoid the assumption that the axes and the figure have the same Units.
You might also be interested in the little-documented overobj https://undocumentedmatlab.com/matlab/wp-content/cache/all/articles/undocumented-mouse-pointer-functions/index.html
The current source for overobj() also assumes that the units are pixels, but if you look at the source code it has the proper units conversion inside it, just commented out.
B. Young
le 13 Oct 2023
Thank you, Walter, so much for your explanation and the document you recommended!!!! now I know what it means and I solved my problem just now!!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!