我必须使用 MATLAB 从 Nastran 读取几个结果文件。我需要导入有关位于文件中间的位移矢量的信息(但我知道有关位移的部分开始和结束的行。)。
这些文件的格式如下:
- 它们被分成“页”,每页有固定的行数
- 每个页面都有一个标题,我不需要导入
- 数据列具有固定宽度(以下是文件“一页”的示例)
我在matlab中写过一个函数,但是速度极慢,这个过程是我代码的瓶颈。(这些文件非常大,我需要处理很多):我正在寻找最快的方式来阅读它们。
你有什么想法吗?
谢谢编辑:我已经添加了我的代码
function [TIME,T1,T2,T3,R1,R2,R3]=importdisp(D,L,cst,cst2,filename)
%D first row of the section
%L last row+1 of the section
page=floor((L-D)/cst);
q=zeros((page)*cst2,1);
TIME=q;T1=q;T2=q;T3=q;R1=q;R2=q; R3=q;
for i=0:page-1
startRow=D+i*cst;
endRow=startRow+cst-1;
qq=(1+i*cst2:(i+1)*cst2);
[TIME(qq),~,T1(qq),T2(qq),T3(qq),R1(qq),R2(qq),R3(qq)] = importfile2(filename, startRow, endRow);
end
i=page;
startRow=D+i*57;
endRow=L-1;
[aTIME,~,aT1,aT2,aT3,aR1,aR2,aR3] = importfile2(filename, startRow, endRow);
TIME=[TIME;aTIME];
T1=[T1;aT1];
T2=[T2;aT2];
T3=[T3;aT3];
function [TIME,TYPE,T1,T2,T3,R1,R2,R3] = importfile2(filename, startRow, endRow)
%% Read columns of data as strings:
% For more information, see the TEXTSCAN documentation.
formatSpec = ' %12f %*s %13f %13f %13f %13f %13f %13f';
%% Open the text file.
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, endRow-startRow-6,'HeaderLines',startRow+6, 'ReturnOnError', false);
fclose(fileID);
TIME = cell2mat(dataArray(1));
TYPE = [];%
T1 = cell2mat(dataArray(2));
T2 = cell2mat(dataArray(3));
T3 = cell2mat(dataArray(4));
R1 = cell2mat(dataArray(5));
R2 = cell2mat(dataArray(6));
R3 = cell2mat(dataArray(7));
R1=[R1;aR1];
R2=[R2;aR2];
R3=[R3;aR3];
1 MSC.NASTRAN JOB CREATED ON 23-JUL-13 AT 11:37:55 JULY 30, 2013 MSC.NASTRAN 11/25/11 PAGE 375
TIME_DIPENDENT
0 SUBCASE 1
POINT-ID = 51
D I S P L A C E M E N T V E C T O R
TIME TYPE T1 T2 T3 R1 R2 R3
1.010000E+00 G 3.575517E-05 0.0 -2.498832E-05 0.0 -1.368603E-06 0.0
1.010200E+00 G 3.615527E-05 0.0 5.931119E-05 0.0 2.523460E-08 0.0
1.010400E+00 G 3.643431E-05 0.0 1.400531E-04 0.0 1.428176E-06 0.0
1.010600E+00 G 3.690420E-05 0.0 2.124308E-04 0.0 1.886763E-06 0.0
1.010800E+00 G 3.727554E-05 0.0 2.720885E-04 0.0 1.029395E-06 0.0
1.011000E+00 G 3.753303E-05 0.0 3.154415E-04 0.0 -5.155680E-07 0.0
1.011200E+00 G 3.799178E-05 0.0 3.399170E-04 0.0 -1.612602E-06 0.0
1.011400E+00 G 3.847007E-05 0.0 3.440528E-04 0.0 -1.544716E-06 0.0
1.011600E+00 G 3.878193E-05 0.0 3.275930E-04 0.0 -3.747878E-07 0.0
1.011800E+00 G 3.927647E-05 0.0 2.914786E-04 0.0 1.095575E-06 0.0
1.012000E+00 G 3.994424E-05 0.0 2.378519E-04 0.0 1.759643E-06 0.0
1.012200E+00 G 4.034076E-05 0.0 1.699633E-04 0.0 1.095494E-06 0.0
1.012400E+00 G 4.074808E-05 0.0 9.188905E-05 0.0 -3.884768E-07 0.0
1.012600E+00 G 4.135053E-05 0.0 8.304626E-06 0.0 -1.629274E-06 0.0
1.012800E+00 G 4.170949E-05 0.0 -7.576412E-05 0.0 -1.752396E-06 0.0
1.013000E+00 G 4.199858E-05 0.0 -1.552350E-04 0.0 -6.461957E-07 0.0
1.013200E+00 G 4.248216E-05 0.0 -2.252832E-04 0.0 8.903658E-07 0.0
1.013400E+00 G 4.278283E-05 0.0 -2.817524E-04 0.0 1.804066E-06 0.0
1.013600E+00 G 4.301732E-05 0.0 -3.213745E-04 0.0 1.573536E-06 0.0
1.013800E+00 G 4.358916E-05 0.0 -3.417496E-04 0.0 3.442360E-07 0.0
1.014000E+00 G 4.405503E-05 0.0 -3.414665E-04 0.0 -1.139860E-06 0.0
1.014200E+00 G 4.437157E-05 0.0 -3.203563E-04 0.0 -1.834472E-06 0.0
1.014400E+00 G 4.499020E-05 0.0 -2.795874E-04 0.0 -1.277272E-06 0.0
1.014600E+00 G 4.558231E-05 0.0 -2.215368E-04 0.0 2.333646E-08 0.0
1.014800E+00 G 4.597261E-05 0.0 -1.495850E-04 0.0 1.129674E-06 0.0
1.015000E+00 G 4.643634E-05 0.0 -6.810582E-05 0.0 1.298742E-06 0.0
1.015200E+00 G 4.685981E-05 0.0 1.765095E-05 0.0 4.973296E-07 0.0
1.015400E+00 G 4.722315E-05 0.0 1.022117E-04 0.0 -5.859554E-07 0.0
1.015600E+00 G 4.764707E-05 0.0 1.804387E-04 0.0 -1.191458E-06 0.0
1.015800E+00 G 4.799638E-05 0.0 2.476246E-04 0.0 -9.108963E-07 0.0
1.016000E+00 G 4.831509E-05 0.0 2.995918E-04 0.0 1.032815E-07 0.0
1.016200E+00 G 4.872533E-05 0.0 3.330215E-04 0.0 1.085160E-06 0.0
1.016400E+00 G 4.917991E-05 0.0 3.459135E-04 0.0 1.281773E-06 0.0
1.016600E+00 G 4.956298E-05 0.0 3.376274E-04 0.0 5.597767E-07 0.0
1.016800E+00 G 4.989865E-05 0.0 3.085430E-04 0.0 -5.647819E-07 0.0
1.017000E+00 G 5.048857E-05 0.0 2.602277E-04 0.0 -1.257802E-06 0.0
1.017200E+00 G 5.116086E-05 0.0 1.957408E-04 0.0 -1.047838E-06 0.0
1.017400E+00 G 5.149745E-05 0.0 1.192598E-04 0.0 -1.662111E-07 0.0
1.017600E+00 G 5.192366E-05 0.0 3.549325E-05 0.0 7.763596E-07 0.0
1.017800E+00 G 5.251750E-05 0.0 -5.053262E-05 0.0 1.131500E-06 0.0
1.018000E+00 G 5.280536E-05 0.0 -1.334662E-04 0.0 6.140833E-07 0.0
1.018200E+00 G 5.301622E-05 0.0 -2.081115E-04 0.0 -3.166196E-07 0.0
1.018400E+00 G 5.345660E-05 0.0 -2.701173E-04 0.0 -8.439085E-07 0.0
1.018600E+00 G 5.390675E-05 0.0 -3.158737E-04 0.0 -5.923507E-07 0.0
1.018800E+00 G 5.422348E-05 0.0 -3.423101E-04 0.0 1.950982E-07 0.0
1.019000E+00 G 5.467689E-05 0.0 -3.474040E-04 0.0 9.392950E-07 0.0
1.019200E+00 G 5.521453E-05 0.0 -3.307139E-04 0.0 1.020770E-06 0.0
1.019400E+00 G 5.565249E-05 0.0 -2.932987E-04 0.0 2.693299E-07 0.0
1.019600E+00 G 5.617935E-05 0.0 -2.372591E-04 0.0 -8.091097E-07 0.0
1.019800E+00 G 5.678378E-05 0.0 -1.657268E-04 0.0 -1.504755E-06 0.0