loading file using uigetfile
古いコメントを表示
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
3 件のコメント
S1=load(uigetfile('*.*','SELECT INPUT DATA'));
S=fft(S1);
Walter Roberson
2025 年 4 月 16 日
移動済み: Voss
2025 年 4 月 16 日
The first output from uigetfile is just the file name itself, without any directory information. If the file might not be in the current directory then you need something more like
[filename, pathname] = uigetfile('*.*','SELECT INPUT DATA');
S1 = load(fullfile(pathname, filename));
After that, the proper steps will depend upon the kind of file that was loaded. load() of an arbitrary file
- might well fail, if the file is not one of a few very specific formats
- might result in a numeric array
- might result in a struct() with one field for each variable name loaded, if it was a .mat file
The cases that result in a numeric array are almost always better handled by readmatrix(). The cases that deal with .mat files need to reference the variable name that the data is stored in. The cases of a .mat file that has a single variable name stored in it can be handled with a small bit of code.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Large Files and Big Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!