Import data from .DTA file to Matlab.

188 ビュー (過去 30 日間)
Mohamed Asaad
Mohamed Asaad 2022 年 2 月 10 日
コメント済み: JBA Miller 2022 年 2 月 12 日
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));
  2 件のコメント
Mohamed Asaad
Mohamed Asaad 2022 年 2 月 10 日



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
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 件のコメント
JBA Miller
JBA Miller 2022 年 2 月 12 日
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 Center および File ExchangeData Import and Analysis についてさらに検索




Community Treasure Hunt

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

Start Hunting!

Translated by