Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
How to: Handling between functions
조회 수: 1 (최근 30일)
이전 댓글 표시
I want to select a certain file then use that file for calculation.
Currently I constantly need to select it for every calculation;
[filename, pathname] = uigetfile({'*.xls'},'File Selector');
[num, txt]=xlsread(filename);
what I want is, select file in:
function OpenMenuItem_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.xls'},'File Selector');
then use for example the 'filename' in a different function:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
cla;
popup_sel_index = get(handles.popupmenu1, 'Value');
switch popup_sel_index
case 1
how do i call the previous selected filename to this function?
댓글 수: 0
답변 (1개)
Jan
2012년 12월 17일
편집: Jan
2012년 12월 17일
You can store the file name for later access:
[filename, pathname] = uigetfile({'*.xls'},'File Selector');
[num, txt]=xlsread(filename);
handles = guidata(FigureHandle); % If not done before
handles.File = fullfile(pathname, filename); % Prefer full filenames
guidata(FigureHandle, handles);
...
function pushbutton1_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
disp(handles.File)
This topic has been discussen frequently, such that searching in the forum will reveal other examples. Another good point to start from are Matt Fig's 41 GUI examples.
댓글 수: 2
Jan
2012년 12월 17일
[Moved from Answer section to Comment section]:
Matlab newbie has written:
I tried your code but I dont get it. Doesnt work.
I want to get that filename including data in the function pushbutton.
Jan
2012년 12월 17일
@Matlab newbie: Please post comments in the comment section. Thanks.
"It does not work" is not detailed enough to suggest an improvement. If you want to store the data in addition, simply do this.
[num, txt]=xlsread(filename);
handles.FileData = num;
It is exactly the same method as for the file name.
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!