numbering in the listbox??
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Well I have a push button and a listbox, and I made a code that when I click on the push button, an entry will be added to the listbox,and as long as I click on the push button, more entries will be added etc.... Also I made another push button to remove the entry that I will not use in the list box. and now what I want is when I click on the push button to add an entry and it asks me to enter the name of the entry to number automatically the entries that I add, so when I add a first entry it will be numbered automatically 1 etc...
Here is the code I used for the "Add entry" push button:
% --- Executes on button press in pushbutton3. % Add Layer function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
prompt=('please enter the name of the layer you wish to add: '); name=('input component name'); numlines=1; defaultanswer={''};
% prompt the user for some input answer = inputdlg(prompt,name,numlines,defaultanswer,'on'); % get the current list box selections selections = get(handles.listbox1,'String'); % append the answer to the list selections = [selections ; answer]; % update the list box with the new selection set(handles.listbox1,'String',selections);
and as I said what I want is to find out how to make the numbering of the entries automatically
5 Kommentare
Jan
am 14 Jul. 2014
@Jihad: Please insert all useful information in the question, and not in comments. You can edit the question easily.
Antworten (1)
Image Analyst
am 14 Jul. 2014
Didn't we just see this somewhere? Someone told you to use sprintf() to make up the string with the numbers in there. To be robust you can examine what the user typed in and if they put in a number, adjust your ordering. If they didn't, just add it to the end with a number one greater than what's already there.
2 Kommentare
Jan
am 14 Jul. 2014
@Jihad: Then show us, what you have tried and explain the poblems. It is impossible to suggest an improvement to your code based on "it did not work".
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!