Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Elif
Elif le 25 Août 2021
Commenté : Elif le 26 Août 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}

Réponse acceptée

Voss
Voss le 25 Août 2021
Modifié(e) : Voss le 25 Août 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);
  1 commentaire
Elif
Elif le 26 Août 2021
Thank you so much for your response.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by