Borrar filtros
Borrar filtros

How can I add a new value to my array with pushbutton?

2 visualizaciones (últimos 30 días)
Elif
Elif el 25 de Ag. de 2021
Comentada: Elif el 26 de Ag. de 2021
I have values which I get it from editbox and listbox but each time I click to pushbutton I lost the previous values. My wish is to add all this values into an array. Now, the outputs are like this:
[5]
[0,10]
[0,0,25]
But, I want it like this: [5,10,25] . How can I do this?
My pushbbutton callback function is in below:
function pushbutton2_Callback(hObject, eventdata, handles)
index = get(handles.listbox1,'value');
handles.a{index}=str2num(get(handles.edit_text,'String'));
handles.b{index}=(handles.a{index}/2);
set(handles.res_txt,'string',handles.b{index});
A(index)=handles.b{index}

Respuesta aceptada

Voss
Voss el 25 de Ag. de 2021
Editada: Voss el 25 de Ag. de 2021
The variable A is a local variable in the function pushbutton2_Callback. Each time the callback executes a new A is created; that's why each A you see has a value only at last index.
handles.b should have what you want, except you have to store the handles structure back into the GUI after you modify the handles structure (i.e., after setting handles.a{index} and handles.b{index}), so that the value of handles.b (and anything else in handles) is up-to-date each time pushbutton2_Callback (or any other function) is called. You can do this by adding this line at the end of pushbutton2_Callback:
guidata(hObject,handles);

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by