Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Listbox and Edit Little HELP pls

Subject: Listbox and Edit Little HELP pls

From: Alric Gta

Date: 8 Apr, 2009 16:24:01

Message: 1 of 4

I want to have a LISTBOX on the same gui, that lists the elements entered by the user in EDIT and gets diplayed in the LISTBOX at a push of a button and the LISTBOX gets updated each time a new element is entered, but keeps displaying the previous added elements (basically a list box that 'grows' each time new data is entered)


Here my code
---------------------------------------------------------------------------------------------------------------
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

prev_str = get(handles.listbox1, 'String');

prev_str{end + 1}= 'Test' ;

set(handles.listbox1, 'String', prev_str, 'Value', length(prev_str));

OBSEVATION
    - this way is working but as you can see text is wrote in the prg and I don't want like this.I mean I want to use an EDIT to enter what ever I want to be displayed in the LISTBOX.
----------------------------------------------------------------------------------------------------------------
So I've made the following modification but doesn't work
Code with modification
---------------------------------------------------------------------------------------------------------------
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

prev_str = get(handles.listbox1, 'String');
my_text=get(handles.edit1,'String');
prev_str{end + 1}= my_text ;

set(handles.listbox1, 'String', prev_str, 'Value', length(prev_str));

I get this err: ===== Invalid cell array of strings ====

Anybody,Somebody.... pls a little help what do i need to modified or ADD
Thanx

Subject: Listbox and Edit Little HELP pls

From: trancemissionxxi@gmail.com

Date: 8 Apr, 2009 17:24:56

Message: 2 of 4

> function pushbutton1_Callback(hObject, eventdata, handles)
> % hObject handle to pushbutton1 (see GCBO)
> % eventdata reserved - to be defined in a future version of MATLAB
> % handles structure with handles and user data (see GUIDATA)
>
> prev_str = get(handles.listbox1, 'String');
> my_text=get(handles.edit1,'String');
> prev_str{end + 1}= my_text ;
>
> set(handles.listbox1, 'String', prev_str, 'Value', length(prev_str));
>
> I get this err: ===== Invalid cell array of strings ====
>

just change the line

prev_str{end + 1}= my_text ;

to

prev_str{end + 1}= {my_text} ;

Subject: Listbox and Edit Little HELP pls

From: Nikoleta argyrou

Date: 6 May, 2009 09:31:01

Message: 3 of 4

"Alric Gta" <alric2rei@yahoo.com> wrote in message <grij31$48q$1@fred.mathworks.com>...
> I want to have a LISTBOX on the same gui, that lists the elements entered by the user in EDIT and gets diplayed in the LISTBOX at a push of a button and the LISTBOX gets updated each time a new element is entered, but keeps displaying the previous added elements (basically a list box that 'grows' each time new data is entered)
>
hello ..first sorry for my english.i just start matlab .i have a gui similar to yours..you help me a lot with your code but still need help..
the main differences are: EDIT=vector of coefficients input in form [ 1 2 3 4] LISTBOX=polynomial roots ..can you help me with the code?pls

Subject: Listbox and Edit Little HELP pls

From: Nikoleta argyrou

Date: 6 May, 2009 09:34:01

Message: 4 of 4

"Alric Gta" <alric2rei@yahoo.com> wrote in message <grij31$48q$1@fred.mathworks.com>...
> I want to have a LISTBOX on the same gui, that lists the elements entered by the user in EDIT and gets diplayed in the LISTBOX at a push of a button and the LISTBOX gets updated each time a new element is entered, but keeps displaying the previous added elements (basically a list box that 'grows' each time new data is entered)
>
hello ..first sorry for my english.i just start matlab .i have a gui similar to yours..you help me a lot with your code but still need help..
the main differences are: EDIT=vector of coefficients input in form [ 1 2 3 4] LISTBOX=polynomial roots ..can you help me with the code?pls

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us