Import data from .DTA file to Matlab.

166 views (last 30 days)
Hi!
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]);
and:
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));
  2 Comments
Highphi
Highphi on 10 Feb 2022
can you drop a sample of the .dat file? It could very well be the case that you can't import that filetype and you'll have to export it in another application before being able to import the data.

Sign in to comment.

Accepted Answer

Highphi
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
delete(filename2);
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 :)
  2 Comments
Mohamed Asaad
Mohamed Asaad on 10 Feb 2022
WOW! What a great simply explained answer! Thank you very much!
JBA Miller
JBA Miller on 12 Feb 2022
Hey!
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)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!