import from .dat file abaqus

hi all,
I try to import certain lines from my .dat file, generated from abaqus. However something strange happens. When I try to import the certain lines with use of Import Data button, select my lines and import it as a table and write it as a function 'importfile'. Then It's not importing the lines I want, but an arbitrary selection, even though the corresponding rows match. However if I copy and paste data from my abaqus generated .dat file, to an empty .dat file, open that one in matlab and select the lines I want to import, then it dóes import the correct lines.
Anyone a clue what is happening here? I tried almost all features in the Import Data toolbox, such as writing it as a different file (table, cell, etc.) but nothing works so far. The file is pretty large, can there be a problem?
I uploaded the file, I need the following data points, for every increment I need the values on the column below the PU2 and the frequency. Is someone keen to help me out? :)
NODE FOOT- U1 U2 PU1 PU2
NOTE
3739 9.4520527E-02 -1.9431870E+00 9.5103755E-02 1.9543827E+00
3739 SSD 1.0516381E-02 -2.0889238E-01 6.3486346E+00 -1.7386427E+02
INCREMENT NUMBER 31
FREQUENCY = 78.976194

5 个评论

Counter = 1;
FID = fopen('results.txt', 'rt');
tline = fgetl(FID);
File_Data{Counter} = tline;
while ischar(tline)
Counter = Counter+1;
tline = fgetl(FID);
File_Data{Counter} = tline;
end
fclose(FID);
File_Data = File_Data';
This will give you your file cell variable File_Data.
You will probably have to find a cell that contains 'INCREMENT NUMBER', example, Increment number is line 8, then you take 8-3, 8-4, 8 and 8+1 line for a single increment number.
% 1 NODE FOOT- U1 U2 PU1 PU2
% 2 NOTE
% 3
% 4 3739 9.4520527E-02 -1.9431870E+00 9.5103755E-02 1.9543827E+00
% 5 3739 SSD 1.0516381E-02 -2.0889238E-01 6.3486346E+00 -1.7386427E+02
% 6
% 7
% 8 INCREMENT NUMBER 31
% 9 FREQUENCY = 78.976194
I would not know how this code below would work, but you can use some ideas from it.
Wanted_Rows = 1:1:length(File_Data);
Delete_Lines = [1:13 114 115 216 217, length(File_Data)]; % Last line of File_Data is -1 which denotes end of file so we remove it here
File_Data(Delete_Lines) = [];
File_Data_Split = split(File_Data(1:length(File_Data))); % Splits the cell
Data_Ready = cellfun(@str2num,File_Data_Split);
@Mario & @KSSV, great posts, thanks, the first bit helps me a lot. Now it imports the .dat file in one cell element. Also, when I now call for the lines I want (in the first place for one increment) I get the following:
File_Data =
3×1 cell array
{' 3739 6.9484012E-02 -1.4426835E+00 6.9688737E-02 1.4466171E+00 '}
{' 3739 SSD 5.3377998E-03 -1.0660863E-01 4.3928653E+00 -1.7577375E+02 '}
{' FREQUENCY = 79.918425 ' }
This is nice!!
However, when I implement the ideas of your second part of the script, it's not yet working. Did some small research, providing the same procedure of cellfun(@str2num,Data, 'uniformoutput', false). With minor edits, such as including 'uniformoutput', false, I do get a cell output, but only with double numbers of the first row.
Data_Ready =
3×1 cell array
{1×5 double}
{0×0 double}
{0×0 double}
this can be converted with cell2mat to numeric values, but that's only the first row..
So my question now is how do I convert this cell structure into (at least) the numeric values I'm interested in (values below PU2 and the frequency)?
Found it! forgot the split function, with use of the following extra scripting, it works!! Thanks a lot for your time and attention :)
Wanted_row = [45994 45995 45999]
File_Data_1 = File_Data(Wanted_row)
row1 = split(File_Data_1{1})
row2 = split(File_Data_1{2})
frequency = split(File_Data_1{3})
cell2mat(cellfun(@str2num,row1,'uniformoutput',false))
cell2mat(cellfun(@str2num,row2,'uniformoutput',false))
cell2mat(cellfun(@str2num,frequency,'uniformoutput',false))
Great to hear it works, KSSV's solution might be more appropriate when you would like to generalise the information extraction, without writing down the wanted rows like in that example.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by