필터 지우기
필터 지우기

Toggling Shift button in Calculator GUI

조회 수: 1 (최근 30일)
Muhammad Ali Qadar
Muhammad Ali Qadar 2012년 12월 20일
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.

채택된 답변

Jan
Jan 2012년 12월 20일
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
Jan
Jan 2012년 12월 20일
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 2012년 12월 20일
편집: Muhammad Ali Qadar 2012년 12월 24일
yes that's very nicely working, Thank You so much.
regards.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming Utilities에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by