请教如何用matlab读取从nastran导出的刚度质量阵pch文件?
通过命令SOL 103
$ Direct Text Input for Executive Control
DIAG 8
$
COMPILE SEMG $
ALTER 'KJJZ.*STIFFNESS' $
ALTER 'MJJX,.*MASS' $
MATPCH KJJZ,MJJX, , // $$
$
CEND
导出了刚度阵、质量阵pch文件(附件),请问有什么方法用matlab读取成矩阵形式?
多谢
%this program is to read the mass matrix and the stiffness matrix
%KAAX the stiffness matrix
%MAAS the mass matrix
% DMIG KAAX 0 6 2 0 273(dof)
% DMIG* KAAX 1(node) 1(x)
% * 1(node) 1(x) 5.087395182D+07
% DMIG* KAAX 1 2
% * 1 1 1.999892380D+07
% * 1 2 5.087395182D+07
% DMIG* KAAX 1 6
% * 1 1-5.470769237D+01
% * 1 2 5.470769237D+01
% * 1 6 2.779150772D+00
% DMIG* KAAX 2 1
% * 1 1-2.933333642D+07
% * 1 2 1.537383915D+06
% * 2 1 1.017479036D+08
% there are 91 node and each node has 3 freedome, so the matrix is a square
% demension 273 matrix
clc
clear all
pretitle='plate_quad';
Nnode=2;
Nfreq=101;
titleB=(['D:\chongxinyuan\Dropbox\matlab\FEM_BEM\',pretitle,'.pch']);
% titleB=(['F:\patranData\',pretitle,'.pch']);
% titleB=(['D:\chongxinyuan\',pretitle,'.f06']);
fid = fopen(titleB, 'r');
dof=273;
Kaax=zeros(dof);
Maax=zeros(dof);
h=1;
column=0;
while ~feof(fid)
tline=fgetl(fid);
if (length(tline)==56) && strcmp(tline(9:12),'KAAX')==1
column=column+1;
elseif length(tline)==56 && (str2num(tline(40))==1 || str2num(tline(40))==2)
lin=(str2num(tline(23:24))-1)*3+ str2num(tline(40));
Kaax(lin,column) =str2num(tline(41:55));
elseif length(tline)==56 && str2num(tline(40))==6
lin=(str2num(tline(23:24))-1)*3+ 3;
Kaax(lin,column) =str2num(tline(41:55));
elseif (length(tline)==56) && strcmp(tline(9:12),'MAAX')==1 % don't mix the mass matrix
break
end
end
fclose(fid);
massok=0;
column2=0;
fid1 = fopen(titleB, 'r');
while ~feof(fid1)
tline=fgetl(fid1);
if length(tline)==72
massok=massok+1; % determine where is the mass matrix
elseif (length(tline)==56) && strcmp(tline(9:12),'MAAX')==1 && massok==2
column2=column2+1;
elseif length(tline)==56 && (str2num(tline(40))==1 || str2num(tline(40))==2) && massok==2
lin=(str2num(tline(23:24))-1)*3+ str2num(tline(40));
Maax(lin,column2) =str2num(tline(41:55));
elseif length(tline)==56 && str2num(tline(40))==6 && massok==2
lin=(str2num(tline(23:24))-1)*3+ 3;
Maax(lin,column2) =str2num(tline(41:55));
end
end
fclose(fid1); 今天刚刚写的,试过可以用。注意修改下dof
对了,因为里面是双数度D,如 1.999892380D+07,要用替换,替换成E,不然读取有错误。 回复 5 # yuanchongxin 的帖子
太感谢了,真是解决了燃眉之急啊,多谢! 为甚么我用上面的代码输入,Nastran闪退,pch文件无法生成?
页:
[1]