필터 지우기
필터 지우기

fopen gives negative fid in GUI

조회 수: 6 (최근 30일)
Ante
Ante 2013년 5월 22일
I started a GUI using GUIDE. I have a browse button that uses uigetdir to get path to folder where I have some excel files, that later on I will read with my script. Problem is in fopen who gives message: No such file or dir. I used debugger and went step by step and to me everything seems to be ok, file path is correctly stored, I don't know what could be the problem. I tried with uigetfile but he only gets path to specific file, and I will have maybe 400 files in that folder.
Help is greatly appreciated.
This part of the code is from gui:
function Browse_1_Callback(hObject, eventdata, handles)
% hObject handle to Browse_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
FileName = uigetdir;
handles.FileName = FileName;
guidata(hObject,handles)
This part from script that runs after button press:
myFolderPV = handles.FileName;
PVFiles = dir(fullfile(myFolderPV,'*.js'));
numfilesPV= length(PVFiles);
for k = 1:numfilesPV
[fid, message] = fopen(PVFiles(k).name);
...

채택된 답변

Iain
Iain 2013년 5월 22일
Your filename is wrong.
You need to have the full path and filename for fopen to work.
[myfolderPV '\' PVFiles(k).name] is your full filename.
  댓글 수: 2
Ante
Ante 2013년 5월 22일
Thank you so much!
Jan
Jan 2013년 5월 22일
Or slightly more flexible:
[fid, message] = fopen(fullfile(myFolderPV, PVFiles(k).name));

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

추가 답변 (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