loading file using uigetfile
10 ビュー (過去 30 日間)
I wrote a few lines of codes to open a file containing a list of words, but it doesn't seem to open any file when I choose the file from the dialogue box. Can anybody tell what did I do wrong somewhere? I dont think the 'return' code was the problem because when i set it into comment, the error still existed.
[FILENAME, pathname] = uigetfile('*.wsb', 'rt');
if (isequal(FILENAME,0) || isequal(pathname,0))
disp('User pressed cancel');
disp(['User selected', fullfile(pathname, FILENAME)]);
fid = fopen(FILENAME,'rt');
%error could not find the file
Walter Roberson 2011 年 11 月 20 日
You need to fopen fullfile(pathname, FILENAME) rather than just FILENAME, except in the case where the chosen file just happens to be in the current directory.
I notice that you provide 'rt' as the second argument to uigetfile(). Does 'rt' happen to be what you want to prompt the user with? Not out of the question, of course, but that would be unusual: the 'rt' suggests confusion with the 'rt' argument that would need to be provided to the fopen() function [which you have done].