フィルターのクリア

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

2 ビュー (過去 30 日間)
Elif
Elif 2021 年 8 月 25 日
コメント済み: Elif 2021 年 8 月 26 日
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);
  1 件のコメント
Elif
Elif 2021 年 8 月 26 日
Thank you so much for your response.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by