MATLAB Answers

How to Add Each Click on Count Result Screen

14 views (last 30 days)
Hi,
I would like to add extra mouse clicks to my count result screen. The related part of the code is:
Num = numel(s);
message= sprintf(' %i Seeds',Num);
h=msgbox(message);
What I have as a screen is:
I would like to add each mouse clicks to the count result screen. Clicking on image one time "152 Seeds" will be "153 Seeds". Two clicks 154 Seeds etc. and goes on. I have also reached to the manual click counter but it provides output on command line of matlab.
How could I add each click to the count result screen?

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 7 Sep 2018
msgbox returns a figure object. It would be possible to find the handle of the text string and update the String property of it. If you are doing a lot of updating then that would probably be best.
However, the easier way is to provide a title when you create the msgbox, and then each time you want to update the count, call msgbox again making sure that you provide the same title. The code will reuse the figure instead of creating a new figure in this case. It still involves more overhead than would be the case for updating the String property of the appropriate object, but it is easier to program.

  5 Comments

Show 2 older comments
Walter Roberson
Walter Roberson on 7 Sep 2018
To work by way of updating:
Num1 = numel(s);
message = sprintf(' %i Stones', Num1);
h = msgbox(message, 'Count Result');
Num2 = count;
message = sprintf('%i Stones', Num2); %not Num1+Num2, count now includes both of them
txt = h.Children(2).Children(1);
txt.String = message;
Murat Kocaman
Murat Kocaman on 10 Sep 2018
My problem has been solved thank you fcor your supports.
Murat Kocaman
Murat Kocaman on 10 Sep 2018
I used below part of the code:
message = sprintf('Click Extra Counts\nHit return when done.');
title(message, 'FontSize', 20);
button = questdlg(message, 'Continue?', 'OK', 'Cancel', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Cancel')
return;
end
while count < 1000 % or whatever failsafe you want.
% User clicks one point. If user types Enter/Return, x is empty.
[x,y] = ginput(1);
if isempty(x)
break;
end
% Put a cross over the point.
plot(x, y, 'o', 'MarkerSize', 24, 'LineWidth', 3);
% down the count.
count = count - 1
% Save coordinates (if desired).
allX(count) = x;
allY(count) = y;
end
Num1 = numel(s);
hold on;
Num2 = count;
message = sprintf('%i Stones', Num2);
h = msgbox(message, 'Count Result');
hold on;
Could you explain this part below?
txt = h.Children(2).Children(1);
txt.String = message;

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!