Error in opening file from another folder, how to fix this problem?
조회 수: 2 (최근 30일)
이전 댓글 표시
I have these codes to open and process a .txt file in MATLAB GUI:
[filename1,filepath1]=uigetfile({'*.txt*','Text Files'},...
'Select Data File');
cd(filepath1);
fp= fopen(filename1);
fgets(fp);
A = textscan(fp, '%f');
fclose(fp);
eee=A{:};
It works perfectly when opening a file in the same directory of the program, can open multiple files with same button. But when opening a second file in another folder directory, I get this error:
Undefined function 'myGUIprogram' for input arguments
of type 'struct'.
Error in
@(hObject,eventdata)myGUIprogram('pushbutton12_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Can anybody help me fix it? Thanks in advance!
댓글 수: 2
dpb
2013년 10월 4일
편집: dpb
2013년 10월 4일
I've not tried it in a gui but per the doc's uigetfile needs must have the MultiSelect property set to On if want to return multiple files and indicates it's Off by default???
It's a cell array returned in that case, not a single string; not sure how to get the callback to handle the difference; I don't do GUIs so not best to ask; just noticed what looks to me like a shortcoming in the call.
But, I can't get it to allow multiple selection across two subdirectories at all -- I don't think that functionality is supported. I don't know about why the crash, though.
ADDENDUM: Or perhaps I read the question/problem description incorrectly; you mean a multi-select in a subdirectory other than the working directory, not from two separate subdirectories, maybe...well let's see what's different there -- nothing.
I'm coming to conclusion that the error isn't actually related to the above code--post the full error message in context with line numbers and all, not just the error text.
채택된 답변
Walter Roberson
2013년 10월 5일
After you cd() to a directory and handle the files there, cd() back.
Alternately, put the directory that contains myGUIprogram.m into the MATLAB path instead of counting on it to be in the current directory.
Better yet, don't do the cd()
fp = fopen(fullfile(filepath1, filename1))
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!