Reset the variable after every iteration
显示 更早的评论
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 个评论
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
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Just for fun 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

