importing text file using uigetfile

11 ビュー (過去 30 日間)
Achmad Fachturrohman
Achmad Fachturrohman 2021 年 4 月 23 日
I'm trying to open text file using uigetfile with the data like this
and code like this
[filename, pathname] = uigetfile('*.txt', 'Open file .txt');
if isequal(filename, 0) || isequal(pathname, 0)
disp('File input canceled.');
else
data = fopen(filename,'r');
end;
anyone who can help me I would really appreciate it. Thank you

採用された回答

Walter Roberson
Walter Roberson 2021 年 4 月 23 日
[filename, pathname] = uigetfile('*.txt', 'Open file .txt');
if isequal(filename, 0)
disp('File input canceled.');
else
filename = fullfile(pathname, filename);
[fid, msg] = fopen(filename,'r');
if fid < 0
error('Failed to open file "%s" because "%s"', filename, msg);
end
%at this point, do whatever it is you were going to do with the file
%identifier
end
I would suggest, though, that it would be easier to use
[filename, pathname] = uigetfile('*.txt', 'Open file .txt');
if isequal(filename, 0)
disp('File input canceled.');
else
filename = fullfile(pathname, filename);
data = readmatrix(filename, 'headerlines', 2);
end
  1 件のコメント
Achmad Fachturrohman
Achmad Fachturrohman 2021 年 4 月 23 日
How do I ignore the first 2 lines of my text data? please help I am newbie in matlab

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by