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

1 visualizzazione (ultimi 30 giorni)
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}

Risposta accettata

Voss
Voss il 25 Ago 2021
Modificato: Voss il 25 Ago 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);

Più risposte (0)

Categorie

Scopri di più su Images in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by