How to load .dat (or even .txt ) files into matlab workspace?
8 ビュー (過去 30 日間)
古いコメントを表示
Hello
I am new to matlab. I am trying to load .dat files from another folder into matlab. I could use .txt files if that is easier.
Here is code I am using:
directory_name=uigetdir(pwd,'Select data directory');
directory_name=([directory_name '\']);
directory_name=uigetdir(pwd,'Select data directory');
directory_name=([directory_name '\'])
files=dir([directory_name,'*.dat'])
This opens the diretory and I am able to choose the folder of choice. However it does not load the file only the filename. In the matlab workspace it shows that file structure to be 1X1.
If I add the following lines:
filename=files.name;
data=load(filename);
I get the following error, of course:
Error using load
Unable to read file 15a001sen2.dat: No such file or
directory.
Please advise how to load files. thanks!
2 件のコメント
Walter Roberson
2017 年 5 月 14 日
Mrittika Mahbub
I already gave an example.
However, there is no standard format for .dat files. You need to know the format of the particular .dat files you are interesting in to know the commands needed to load in the data.
採用された回答
Walter Roberson
2013 年 2 月 25 日
[filename directory_name] = uigetfile('*.dat', 'Select a file');
fullname = fullfile(directory_name, filename);
data = load(fullname);
その他の回答 (1 件)
Azzi Abdelmalek
2013 年 2 月 25 日
編集済み: Azzi Abdelmalek
2013 年 2 月 25 日
fid = fopen([yourpath '/' 'file.txt']);
line1 = fgetl(fid);
res=line1;
while ischar(line1)
line1 = fgetl(fid);
res =char(res,line1)
end
fclose(fid);
res
参考
カテゴリ
Help Center および File Exchange で Workspace Variables and MAT Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!