How to concatenate strings from multiple push button?
이전 댓글 표시
Hey, I want a gui with four push buttons. Say, push button 1 gives an output of A, pb2 B, pb3 C and pb4 D. What I want to do is, I like to concatenate each letter in one string. That is, everytime a push button is pressed, it will add the new letter to the string. For example, pb1 pb2 pn3 pb4 the output should be A B C D thanks!
답변 (2개)
Walter Roberson
2018년 8월 9일
편집: Walter Roberson
2018년 8월 9일
Initialize:
handles.currentstring = '';
guidata(hObject, handles)
Then you can use the same callback code for all four pushbuttons:
function pushbuttonA_callback(hObject, event, handles)
handles.currentstring = [handles.currentstring hObject.String];
guidata(hObject, handles);
댓글 수: 2
Mark Jecel Rapir
2018년 8월 9일
Walter Roberson
2018년 8월 9일
If you are using GUIDE, then put
handles.currentstring = '';
into the OpenFcn_Callback, and make sure that callback ends with
guidata(hObject, handles)
Then, build the four pushbuttons, setting their String values to 'A', 'B', 'C', and 'D'. Configure the Callback associated with each one of them to contain
handles.currentstring = [handles.currentstring hObject.String];
guidata(hObject, handles);
in all four cases.
You would need slightly different code if you were using R2014a or earlier.
카테고리
도움말 센터 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!