numbering in the listbox??

조회 수: 1 (최근 30일)
Jihad Chamseddine
Jihad Chamseddine 2014년 7월 14일
편집: Jihad Chamseddine 2014년 7월 15일
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
Jihad Chamseddine
Jihad Chamseddine 2014년 7월 14일
and I want the numbers to be shown automatically using a code and not to write them manual, hope you understood my problem
Jan
Jan 2014년 7월 14일
@Jihad: Please insert all useful information in the question, and not in comments. You can edit the question easily.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2014년 7월 14일
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
Jihad Chamseddine
Jihad Chamseddine 2014년 7월 14일
yes but it didn't work
Jan
Jan 2014년 7월 14일
@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".

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dialog Boxes에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by