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

1 次查看(过去 30 天)
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}

采纳的回答

Voss
Voss 2021-8-25
编辑:Voss 2021-8-25
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by