필터 지우기
필터 지우기

Error in opening file from another folder, how to fix this problem?

조회 수: 2 (최근 30일)
Ekin
Ekin 2013년 10월 4일
댓글: Ekin 2013년 10월 6일
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
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.
Ekin
Ekin 2013년 10월 6일
Still multi select but not multi select at the same time, i mean when the button pushed, it loads a file; and push the button again and open another file. The problem is now solved. Thanks anyway.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
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))
  댓글 수: 1
Ekin
Ekin 2013년 10월 6일
Removing cd and changing fp solved the problem, thanks Walter.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by