Import data from .DTA file to Matlab.

222 views (last 30 days)
I need to import data from from .DTA file to plot them in MatLab. Does anybody know an appropriate way to do that? I have tried using these below scripts but no one has worked:
a1_Au1EchemPEG = fileread('John_220202_SE_SPR_PEG_PBS+HydroQ_0,45CV_1.DTA');
b1_Au1EchemPEG = strrep(a1_Au1EchemPEG,',','.');
c1_Au1EchemPEG = sscanf(b1_Au1EchemPEG, '%g', [2, inf]);
a1_Au1EchemPEG = importdata('John_220202_SE_SPR_PEG_PBS+HydroQ_0,45CV_1.DTA');
b1_Au1EchemPEG = strrep(a1_Au1EchemPEG,',','.');
c1_Au1EchemPEG = cell2mat(cellfun(@str2num,b1_Au1EchemPEG ,'un',0));

Sign in to comment.

Accepted Answer

Highphi on 10 Feb 2022
Edited: Highphi on 10 Feb 2022
here is what I was able to do with it:
filename = 'John_220202_SE_SPR_PEG_PBS+HydroQ_0,45CV_1.DTA';
% we really need to work on our file naming convention lol
% copy the file to a legible format
filename2 = [filename(1:end-3), 'txt'];
copyfile(filename, filename2);
% read table of legible file type
T = readtable(filename2, 'ReadVariableNames', 0);
% delete the file that we created bc we don't need it anymore
it successfully imports your file into a table
Hopefully you can take it from here, let me know if you need more assistance.
However, I must note that the end of the file you provided me has this inconsistency:
idk if that's the same for every file or even if you want to include that data since it's the same thing as the headers at the top (I'm assuming it reprints the column variable names every 900 data points)
but you're going to want to write code to parse around that or your data will be impossible to convert. lmk if you need help :)
JBA Miller
JBA Miller on 12 Feb 2022
I read through it and tried to do it myself, however when I try to read in my .dta file there is just garbage in there. Like, I got a table but it is not filled with the actual data but instead with weird signs. Maybe I did smth wrong?
Would be very happy if someone could help me out.
Best & thanks!

Sign in to comment.

More Answers (0)


Find more on Tables in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!