How to increment index value of variable on every click of Push button?
조회 수: 3 (최근 30일)
이전 댓글 표시
I want to set variable A1=1 wen user clicks Push Button1,A2=1 wen user clicks second time the same push button,A3=1 wen user clicks same button for third time,,,like this variable index should increase wenever user clicks the push button ,,
댓글 수: 0
채택된 답변
Jan
2013년 3월 4일
It is much smarter to store the variables as a vector or cell array, such that you can access the value by A{1} or A(1), respectively. Then the button's callback can store the counter in the handles struct:
function buttonCallback(ObjectH, EventData)
handles = guidata(ObjectH);
handles.counter = handles.counter + 1;
handles.A{counter} = 1;
guidata(ObjectH, handles);
Then the counter and the list of variables ist stored in the FIGURE's ApplicationData an can be obtain by GUIDATA.
댓글 수: 0
추가 답변 (1개)
Ajay Pherwani
2013년 3월 4일
how many variables you have ? are the numbers of variables fixed or they may vary ?
If varibales are fixed : suppose we have A1.. to ..An
Assuming last push button hit made An=1 and what should happen when one more push button hits ?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!