Import data from .DTA file to Matlab.

조회 수: 112 (최근 30일)
Mohamed Asaad
Mohamed Asaad 2022년 2월 10일
댓글: JBA Miller 2022년 2월 12일
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
Highphi
Highphi 2022년 2월 10일
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.
Mohamed Asaad
Mohamed Asaad 2022년 2월 10일

댓글을 달려면 로그인하십시오.

채택된 답변

Highphi
Highphi 2022년 2월 10일
편집: Highphi 2022년 2월 10일
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
Mohamed Asaad
Mohamed Asaad 2022년 2월 10일
WOW! What a great simply explained answer! Thank you very much!
JBA Miller
JBA Miller 2022년 2월 12일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by