Importing dat files as a double matrix
古いコメントを表示
I am new in matlab, and I got data stored as dat files and I need to import them as a double matrix
Thanks in advance
Mohamed
3 件のコメント
Voss
2023 年 12 月 4 日
That the file has a .dat extension doesn't say anything about the format of the data it contains. Please upload one of the files (using the paperclip button), so we can see what's what.
Mario
2023 年 12 月 4 日
I tried to upload one of the files, but the website site refused as they don't support Dat files. I got a set of dat files and they were generated from another Matlab function. each file contains 4 columns (X,Y,U,V)
Voss
2023 年 12 月 4 日
You can zip the dat file(s) and upload the zip file.
回答 (1 件)
KALYAN ACHARJYA
2023 年 12 月 4 日
編集済み: KALYAN ACHARJYA
2023 年 12 月 4 日
Example
#Edited (Pls Check Comments)
data = readmatrix('yourfile.dat');
data = double(importdata('yourfile.dat'));
6 件のコメント
Stephen23
2023 年 12 月 4 日
Avoid LOAD for text data.
Avoid IMPORTDATA for text data.
Recommended: READMATRIX, READTABLE, etc.
Mario
2023 年 12 月 4 日
I tried the below command
Vec00001 = readtable("C:\Users\Desktop\results\Post\Vec00001.dat", opts);
but how read the whole set of dat files? I got 1500 dat files and I need to import them all
Dyuman Joshi
2023 年 12 月 4 日
If readtable() works for you, then see the 2nd method using dir() - https://in.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html
KALYAN ACHARJYA
2023 年 12 月 4 日
Yes, thank you all....I missed it.
Mario
2023 年 12 月 5 日
I used the below command and it read the dat files as a table (1x1500 cell) and each cell include (65536x4 table)
for k = 1:1500
myfilename = sprintf('Vec%05d.dat', k);
mydata{k} = readtable(myfilename);
end
then I tried to convert the table to matrix, but it doesn't work, could you please correct it to me?
for k = 1:1500
mydata1(:,:,k)= table2array(mydata{:,k})
end
Stephen23
2023 年 12 月 7 日
P = 'absolute or relative path to where the files are saved';
N = 1500;
C = cell(1,N);
for k = 1:N
F = sprintf('Vec%05d.dat',k);
C{k} = readmatrix(fullfile(P,F));
end
A = cat(3,C{:});
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!