gmmread.m

来自「一个关于数据聚类和模式识别的程序,在生物化学,化学中因该都可以用到.希望对大家有」· M 代码 · 共 76 行

M
76
字号
function gmm=gmmRead(gmmFile)
%gmmRead: Read GMM from a file
%	Usage: gmm=gmmRead(gmmFile)
%		gmm: gmm structure
%		gmmFile: output file
%
%	For example:
%		gmm=gmmRead('example.gmm');

%	Roger Jang, 20070903

fid=fopen(gmmFile, 'r');

% ====== Read comments
target='<comment>';
line=fgetl(fid);
if strcmp(line, target)==0, fprintf('line=%s\n', line); error('Cannot find "%s"!\n', target); end
line=fgetl(fid);
gmm.comment=line;
% ====== Read version
target='<version>';
line=fgetl(fid);
if strcmp(line, target)==0, fprintf('line=%s\n', line); error('Cannot find "%s"!\n', target); end
line=fgetl(fid);
gmm.version=line;
% ====== Read gmmType
target='<gmmType>';
line=fgetl(fid);
if strcmp(line, target)==0, fprintf('line=%s\n', line); error('Cannot find "%s"!\n', target); end
line=fgetl(fid);
gmm.gmmType=eval(line);
% ====== Read name
target='<name>';
line=fgetl(fid);
if strcmp(line, target)==0, fprintf('line=%s\n', line); error('Cannot find "%s"!\n', target); end
line=fgetl(fid);
gmm.name=line;
% ====== Read dim
target='<dim>';
line=fgetl(fid);
if strcmp(line, target)==0, fprintf('line=%s\n', line); error('Cannot find "%s"!\n', target); end
line=fgetl(fid);
gmm.dim=eval(line);
% ====== Read mixNum
target='<mixNum>';
line=fgetl(fid);
if strcmp(line, target)==0, fprintf('line=%s\n', line); error('Cannot find "%s"!\n', target); end
line=fgetl(fid);
gmm.mixNum=eval(line);
% ====== Read mean
target='<mean>';
line=fgetl(fid);
if strcmp(line, target)==0, fprintf('line=%s\n', line); error('Cannot find "%s"!\n', target); end
for i=1:gmm.mixNum
	line=fgetl(fid);
	gmm.mean(:,i)=eval(['[', line, ']']);
end
% ====== Read covariance
target='<covariance>';
line=fgetl(fid);
if strcmp(line, target)==0, fprintf('line=%s\n', line); error('Cannot find "%s"!\n', target); end
line=fgetl(fid);
gmm.covariance=eval(['[', line, ']']);
% ====== Read weight
target='<weight>';
line=fgetl(fid);
if strcmp(line, target)==0, fprintf('line=%s\n', line); error('Cannot find "%s"!\n', target); end
line=fgetl(fid);
gmm.weight=eval(['[', line, ']']);
% ====== Read gConst
target='<gConst>';
line=fgetl(fid);
if strcmp(line, target)==0, fprintf('line=%s\n', line); error('Cannot find "%s"!\n', target); end
line=fgetl(fid);
gmm.gConst=eval(['[', line, ']']);
fclose(fid);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?