How to read tabular data from *.DAT files into MATLAB?

Dear all,
just tried to read a *.dat file into MATLAB. Loading the file worked out quite fine.
A=importdata('PIOMAS.vol.daily.1979.2013.Current.v2.dat');
A.data;
However, the resulting data looks strange (binary issue?).
2.0130 0.1490 0.0193
2.0130 0.1500 0.0192
2.0130 0.1510 0.0191
How it should look like
Year #day Vol
1979 1 26.405
1979 2 26.496
1979 3 26.582
1979 4 26.672
1979 5 26.770
1979 6 26.867
1979 7 26.940
1979 8 27.013
1979 9 27.095
1979 10 27.185
Maybe somebody knows how to do the trick. Best regards, Fernandes

2 件のコメント

ebot joel
ebot joel 2019 年 3 月 18 日
M=dlmread('filename.extension')
plot(M(:,1.),M(:,2))
Luis Miguel Ariza Morales
Luis Miguel Ariza Morales 2022 年 10 月 7 日
clear; close all; clc;
A=importdata('nombre_documento.extension');
A.data;
% para ver la primera columna
A.data(:,1); % muestra números en pantalla
% para ver más de una columna
M=[A.data(:,2) A.data(:,3)];
% para graficar lo que deseo:
plot(M(1,1),M(1,2),'.b');
hold on
for i=1:size(M,1)
axis([0 1 0 2]) % en x[0 1]; en y [0 2]
grid on
plot(M(i,1),M(i,2),'.b')
end

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

 採用された回答

Walter Roberson
Walter Roberson 2013 年 6 月 22 日
編集済み: MathWorks Support Team 2018 年 11 月 7 日

5 投票

You can use the “Import Tool” app or the “readtable” function to accomplish this.
Right click on the CSV file and select the “Import Tool”, which will help you through the import process. The Import Tool helps you import the data interactively.
Or use the “readtable” function which imports the data as a table:
T = readtable('myCSVfile.csv');
For more information on using “Import Tool” see:
For more information on using “readtable” see:

13 件のコメント

G
G 2013 年 6 月 22 日
Thank you very much for the fast reply and the proper solution.
Chandra Sekhar Uppu
Chandra Sekhar Uppu 2016 年 8 月 12 日
collect is showing error as unknown option
Walter Roberson
Walter Roberson 2016 年 8 月 12 日
'CollectOutput'
Akshay Kumar
Akshay Kumar 2016 年 9 月 13 日
You can change '1' to '0' in case your first line/character is not read.
gagandeep singh
gagandeep singh 2017 年 4 月 3 日
still i can not got my answer or give error when set to 0.kindly do needful.
Walter Roberson
Walter Roberson 2017 年 4 月 3 日
gagandeep singh please attach a sample of your input file, and your code.
janani subraveti
janani subraveti 2017 年 4 月 9 日
Hi, I need to import a dat file into matlab and my dat file consists of hex data ... how can i do it? I need my imported data to be present as hex data only not as decimal
Walter Roberson
Walter Roberson 2017 年 4 月 9 日
janani subraveti is the file the text representation of hex data, or is it binary numeric data that you need to represent as hex ?
If it is text representation of hex data, then you might be able to read it as strings.
An extract from the file would help organize our thinking.
janani subraveti
janani subraveti 2017 年 4 月 9 日
編集済み: Walter Roberson 2017 年 4 月 9 日
my file is in binary numeric data and inorder to open that file I have to open it with the help of Hex editor tools and i need to import that data into workspace so that i do buffer operation over it and my commands for reading that data are like this but I am facing trouble when i use 'from workspace' block in simulink to get the data from B
fileID = fopen('pet_data.dat');
Onebyte = fread(fileID,'*ubit8');
B=dec2hex(Onebyte);
Image Analyst
Image Analyst 2017 年 4 月 9 日
Walter Roberson
Walter Roberson 2017 年 4 月 9 日
dec2hex() creates character vectors. Simulink signals cannot be characters.
You could
B = double( dec2hex(Onebyte) );
and use that, but for most purposes it is easier to just transfer the byte stream Onebyte . If you had a need to output the bytes in hex format to a serial port you could use https://www.mathworks.com/matlabcentral/fileexchange/5060-rs232-blockset
janani subraveti
janani subraveti 2017 年 4 月 10 日
I could load data from the workspace and could send it to buffer using 'from workspace' block in simulink but instead of that i want to use 'from file' block and for using that i need to store my data into .mat file, how can I do it? and my code is in this way when i used 'from workspace' block when my data is being loaded into my workspace.In the following case, I want to give C to a mat file and use the block 'from file' and load C from it, how can I do that?
clc;
Fs=1000;
Ts=1/Fs;
fileID = fopen('pet_data.dat');
OneByte = fread(fileID,'*ubit8');
A=double(OneByte);
B=[0:Ts:(length(A)-1)/Fs]';
C=[B A];
D=dec2hex(A);
Walter Roberson
Walter Roberson 2017 年 4 月 10 日
ts = timeseries(B, A);
save('pet_ts.mat', 'ts', '-v7.3');
Now From File of pet_ts

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDownloads についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by