Filter löschen
Filter löschen

loading file using uigetfile

10 Ansichten (letzte 30 Tage)
NUR KHAIRUNNISA rahimi
NUR KHAIRUNNISA rahimi am 20 Nov. 2011
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');
else
disp(['User selected', fullfile(pathname, FILENAME)]);
end
fid = fopen(FILENAME,'rt');
if fid<0
%error could not find the file
return,
end

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 20 Nov. 2011
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].
  7 Kommentare
Fangjun Jiang
Fangjun Jiang am 20 Nov. 2011
uigetfile() just brings up a GUI for you to pick a file. Take a look at the help of uigetfile. [FILENAME, pathname] = uigetfile('*.wsb') is sufficient for you to choose from all the .wsb files. If you add the 'w+' as you did, the 'w+' would appear in the title bar in the GUI window that was brought up. It is meaningless and has nothing to do whether you want to write or read the file.
NUR KHAIRUNNISA rahimi
NUR KHAIRUNNISA rahimi am 20 Nov. 2011
thank you, i think i got it now.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by