How to share vector between two callback function?

조회 수: 1 (최근 30일)
Rohit Bhoi
Rohit Bhoi 2016년 2월 28일
편집: Jan 2016년 2월 28일
I have gui in which there is edit text and two push buttons are present namely add and save.whenever i press add it gets value present in edittext and add to vector which is v=[]; now I want to give this vector to save_button_callback function.so that I can write that in excel sheet, so to do that? I haves used following code ;
function add_Callback(hObject, eventdata, handles)
% hObject handle to add (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
v=[];
a=str2num(get(handles.edit1, 'String'));
handles.v=[v a];
function Calculate_Callback(hObject, eventdata, handles)
% hObject handle to Calculate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[fname,pth]=uiputfile('.xls');
handles.v;
handles.m=handles.v;
xlswrite([pth,fname],handles.m,1,'A1');
[EDITED, Jan, Code formmated - please use the "{} Code" button - Thanks]

채택된 답변

Jan
Jan 2016년 2월 28일
편집: Jan 2016년 2월 28일
You got is almost correct. Only update the handles struct store in the figure:
function add_Callback(hObject, eventdata, handles)
v = [];
a = str2num(get(handles.edit1, 'String'));
handles.v=[v a];
guidata(hObject, handles); % <-- add this
Note that the this can be abbreviated, because the empty v is meaningless here:
function add_Callback(hObject, eventdata, handles)
handles.v = str2num(get(handles.edit1, 'String'));
guidata(hObject, handles);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by