How to concatenate strings from multiple push button?
Ältere Kommentare anzeigen
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!
Antworten (2)
KSSV
am 8 Aug. 2018
pb1 = 'A' ;
pb2 = 'B' ;
pb3 = 'C' ;
pb4 = 'D' ;
S = [pb1,' ',pb2,' ',pb3,' ',pb4] ;
Walter Roberson
am 9 Aug. 2018
Bearbeitet: Walter Roberson
am 9 Aug. 2018
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 Kommentare
Mark Jecel Rapir
am 9 Aug. 2018
Walter Roberson
am 9 Aug. 2018
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.
Kategorien
Mehr zu Entering Commands finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!