Get CurrentPoint gives me wrong values after deploying as web app
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I am using appdesigner to develop an application. In the app, I have an axes that plots one image. Once the user clicks the image, it triggers a callback function, as shown below.
him = imagesc(wafermap, 'parent', app.Ax1);
him.ButtonDownFcn = @app.imClicked;
Inside, the callback function, I want to get the X and Y position of the click for some further processing. For convinience, I have output the value to a label.
The codes to get the click position is shown below.
cpt = get(app.Ax1, 'CurrentPointGet ');
pt = cpt(1, 1:2);
x = round(pt(1));
y = round(pt(2));
app.StatusOutput.Text = sprintf('Row: %d, Column: %d', y, x);
The app works very well on my desktop. The problem comes when being deployed as a web app. The returned x and y values can be 0 or minus sometimes. After palying with the web app for a while, I find that the returned x and y values can change when I change the size of the browser. When I use the maximize button on the bottom left corner, the x values are correct while the y value is always minus 1 from the expected value, that's showing 0 if it is actually 1.
By the way, I am using Matlab 2019a on Windows 10 64bit system.
Any thoughts on how to sort out the problem or any workaround?
Thanks a lot.
0 Commenti
Risposte (1)
Georgi Nalbantov
il 23 Ott 2021
Modificato: Georgi Nalbantov
il 23 Ott 2021
Hi, I noticed that (R2019a) when deployed in a browser, the y-axis coordinates are returned vis-a-vis the bottom of the browser window, and not the bottom of the axes. Similar issue exists with the x-axis. This may lead to current point coordinates offsets of 200+ pixels (!), say if you reduce the height of the browser a lot. As you put it, the returned x and y values change when you change the size of the browser. To get around this, what worked for me was:
To get the current point coordinates, use:
cpt = event.IntersectionPoint;
instead of:
cpt = app.UIAxes.CurrentPoint; % this is the same as: get(app.UIAxes, 'CurrentPoint') .
For example, you can have a mouse-move function like this:
% Window button motion function: UIFigure
function UIFigureWindowButtonMotion(app, event)
C = app.UIAxes.CurrentPoint; % C = get(app.UIAxes, 'CurrentPoint');
D = event.IntersectionPoint;
app.xEditField_CP.Value = num2str(round(1000*C(1,1))/1000);
app.yEditField_CP.Value = num2str(round(1000*C(1,2))/1000);
app.xEditField_EI.Value = num2str(round(1000*D(1))/1000);
app.yEditField_EI.Value = num2str(round(1000*D(2))/1000);
app.UIAxes.Toolbar.Visible = 'off';
end
I got inspired by this topic: https://www.mathworks.com/matlabcentral/answers/674218-drawrectangle-not-working-consistently-help
Hope this helps. See attached file app_get_coordinates.mlapp for a complete example.
0 Commenti
Vedere anche
Categorie
Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!