How do you pass coordinates from getrect into a variable?

So I've probably misunderstood this function altogether.
When using GetRect I am trying to return the coordinate and drag distances to a variable. When I do this in my script I can't get it to store the values, only output them to screen.
Simple script I used:
Selection = getrect;
Output I got:
Selection =
-9.6608 -4.0233 4.0111 3.3819
Everytime I seem to instantly lose the values. When I immediately try to access them after they don't exist.

回答(2 个)

Step through your code a line at a time and figure out when Selection vanishes. You're possibly either doing a clear(), or losing scope. If it's the latter, see the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F

2 个评论

Stepping through shows the variable is never actually created. The very next line I start using the four elements to return the window to my main function. For now I am just directly calling it so I don't know why it's disappearing from memory.
The function getrect is supposed to return a 1x4 vector which I have named Selection then want to use the values from.
Here's my code:
%%Choose the Region
Selection = getrect; % Select the Area of Interest Using a Mouse
%%Results
X_Cut_Min = Selection(1,1);
Y_Cut_Min = Selection(1,2);
X_Cut_Max = Selection(1,3) + Selection(1,1);
Y_Cut_Max = Selection(1,4) + Selection(1,2);
Hard to replicate since I don't have your full code. If you want, you can use rbbox() or imrect() instead - they're essentially the same thing. But rbbox() "finishes" as soon as you lift the mouse button while imrect() lets you adjust the sides before "finishing".

请先登录,再进行评论。

I feel like I have discovered something. If I separate the 'getrect' part into a separate function it works. I guess this means something about how I am manipulating the figure is incorrect....

类别

帮助中心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!

Translated by