Reset the variable after every iteration

1 view (last 30 days)
This is a piece of code in which i am trying to work. I have MATLAB GUI where it points the exact locations of clicks. I have eleven variables. So, I want to reset the mouseClick after every run but right now where ever i am clicking i am getting the same output. So how to reset the variable or is there any way to make it work when i am clicking different clicks the value should appear different?
clc
mouseClick = [0.5; 0.3];
buttonNumber = clickpoint(mouseClick)
switch buttonNumber
case 1
disp('F101');
case 2
disp('F102');
case 3
disp('T101');
case 4
disp('T102');
case 5
disp('F105');
case 6
disp('T106');
case 7
disp('T105');
case 8
disp('T104');
case 9
disp('T103');
case 10
disp('C101');
case 11
disp('L101');
end
% rest of the variables
function [buttonName] = clickpoint(a)
% [1 1 2 2] --> F101
% [2 1 3 2] --> t103
position = [0.3189, 0.2189, 0.6320, 0.5320; 0.1927, 0.0927, 0.3883, 0.2883; 0.3180, 0.1180, 0.4174, 0.2174; 0.5303, 0.4303, 0.5302, 0.4302; 0.7071, 0.6071, 0.6528, 0.5528; 0.7277, 0.6277, 0.6528, 0.5528; 0.9107, 0.8107, 0.4419, 0.3419; 0.9710, 0.6710, 0.4276, 0.1276; 0.4246, 0.3246, 0.6509, 0.5509; 0.4246, 0.3246, 0.1785, 0.0785; 0.5771, 0.4771, 0.6556, 0.5556];
% Inputs
%checkpoint = [0.4; 0.2];
% Code to find the box in which the point lies in.
A = [ones(11, 2) position];
M = [diag(a) -diag(a); -eye(2) zeros(2); zeros(2) eye(2)];
buttonName = find(sum(A*M > 0, 2) == 4);
end
  1 Comment
Atsushi Ueno
Atsushi Ueno on 6 Jun 2021
I don't understand about the variable "position" in your code. I thought that the x,y coordinates of multiple rectangles were lined up like the keyboard, but the coordinates are just jumbled together. Also, the order of the coordinates for the upper left corner and the lower right corner do not match.
position = [0.3189 0.2189 0.632 0.532;0.1927 0.0927 0.3883 0.2883;0.318 0.118 0.4174 0.2174;0.5302 0.4302 0.5303 0.4303;0.6528 0.5528 0.7071 0.6071;0.6528 0.5528 0.7277 0.6277;0.4419 0.3419 0.9107 0.8107;0.4276 0.1276 0.971 0.671;0.1785 0.0785 0.6509 0.5509;0.1785 0.0785 0.4246 0.3246;0.5771 0.4771 0.6556 0.5556;];
for i=1:size(position,1)
rectangle('position', [position(i,1), position(i,2), position(i,3)-position(i,1), position(i,4)-position(i,2)])
end

Sign in to comment.

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 6 Jun 2021
>I have MATLAB GUI where it points the exact locations of clicks.
You should isolate the cause of your problem. Your MATLAB GUI returns the clicked coordinates, doesn't it? If you have problem with your MATLAB GUI, you should explain what it is.
>I have eleven variables. So, I want to reset the mouseClick after every run but right now where ever i am clicking i am getting the same output.
That's probably your assumption. Just set coordinate values to "mouseClick" by event hundler of MATLAB GUI you have, then call your "clickpoint()" function to get "buttonNumber". Your "clickpoint()" function does not retain local variables from the last time it was called because they are not persistance variables. So there is no need to reset the local variables in "clickpoint()" function.
>So how to reset the variable or is there any way to make it work when i am clicking different clicks the value should appear different?
You don't need to reset the variables. And you should confirm the "position" values. Yes, your "clickpoint()" function does work (with correct coodinate sets of "position" in it). I guess you wrote random numbers as "position" for this question. Put them back to the original position values.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!