Error in opening file from another folder, how to fix this problem?
3 views (last 30 days)
Show older comments
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 Comments
dpb
on 4 Oct 2013
Edited: dpb
on 4 Oct 2013
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.
Accepted Answer
Walter Roberson
on 5 Oct 2013
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))
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!