Clear Filters
Clear Filters

Toggling Shift button in Calculator GUI

1 view (last 30 days)
I have been Understanding the Calculator already made in Matlab, I have seen that if we click on shift button first time then shift=1 and it remains 1 till we restart the program, So What I want that when I first time click on it, should set shift=1 and if I click again it Should set it to 0 e.g shift=0; I have Problem here
function pushbutton26_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton26 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global jj shift
shift=1;
Can Somebody let me know how can I toggle this button. All of the Files are available here at the following link.

Accepted Answer

Jan
Jan on 20 Dec 2012
This program has been created by GUIDE. This causes ugly names like "pushbutton26_Callback". The shift-status is most likely store in the global variable "shift".
Ugly function names accompanied with global variables and a poor documentation of the code are a bad programming style. I understand that GUIDE is responsible for this, but posting such code and asking others for changes hits a critical point: Any tiny change requires an exhaustive analysis of the code to avoid unwanted side-effects. A really professional advice would be: Do not modify foreign code if it has a low quality already.
It is possible, perhaps you have only change the last line from "shift=1" to "shift=1-shift". But it is tedious to check if this is correct, while it is easy to test if this is working appearently.
  3 Comments
Jan
Jan on 20 Dec 2012
You can add something like this to the callbacks of all concerned buttons:
global shift;
... The processing of the button's function
shift = 0;
Muhammad Ali Qadar
Muhammad Ali Qadar on 20 Dec 2012
Edited: Muhammad Ali Qadar on 24 Dec 2012
yes that's very nicely working, Thank You so much.
regards.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming Utilities in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!