MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

0

how to make a push button to be pressed 3 times after other push button is pressed ?

Dany Majed さんによって質問されました 2019 年 3 月 25 日
最新アクティビティ Dany Majed さんによって コメントされました 2019 年 3 月 25 日
Hello,
so i created two pushbuttons in gui in matlab so let us call the first pushbutton pushbutton1 and lets call the second push button pushbutton2 this is already done but just written this for clarification so my question is how could i make when pushbutton2 is pressed in the gui it causes pushbutton1 to be pressed 3 times after each other since in pushbutton1 i am having a specific functions and plots and matrices so i need the user once he presses the pushbutton2 so it could cause the pushbutton1 that contains functions plots and matrices to be pressed 3 times. Thanks in advance.

  0 件のコメント

サインイン to comment.

製品


リリース

R2018a

1 件の回答

回答者: Kevin Phung
2019 年 3 月 25 日
 採用された回答

You can jsut call out the callback for pushbutton2 three times in your callback for pushbutton1.
button1 = uicontrol('style','pushbutton','callback',@push1callback)
button2 = uicontrol('style','pushbutton','callback',@push2callback)
function push1callback(hObj,event)
%this button gets pushed
disp('first button is pushed')
for i = 1:3
push2callback % runs the second button 3 times.
end
end
function push2callback(hObj,event)
disp('Second button is pushed')
end

  5 件のコメント

no i am just trying to do when pushbutton 2 is pressed it causes push button to be pressed 3 times nothing else i know that i can turn its color to blue directly by setting this downward command in pushbutton2 but i need it for later on so i need to grasp the idea of how when one putton is pressed it causes other button to be pressed 3 times after each other so if you could help me and edit the code that i have sent earlier that would be so much helpful and will be appreciated.
patch([0,1/3,1/3,0],[2/3,2/3,1,1],[0,0,0,0],'blue')
The reason why I asked is becaause you are not using an if/else statement correctly. Your elseifs do not run if a condition before it is satisfied. And, like I said in my answer, you can just use a forloop to run the callback multiple times:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
for i=1:3
pushbutton2_Callback
end
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Thanks it worked i really do appreciate that

サインイン to comment.



Translated by