How to concatenate strings from multiple push button?
Mostra commenti meno recenti
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!
Risposte (2)
KSSV
il 8 Ago 2018
pb1 = 'A' ;
pb2 = 'B' ;
pb3 = 'C' ;
pb4 = 'D' ;
S = [pb1,' ',pb2,' ',pb3,' ',pb4] ;
Walter Roberson
il 9 Ago 2018
Modificato: Walter Roberson
il 9 Ago 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 Commenti
Mark Jecel Rapir
il 9 Ago 2018
Walter Roberson
il 9 Ago 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.
Categorie
Scopri di più su Entering Commands in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!