0

在 Matlab 中运行函数时出现此错误

“使用 fseek 时出错 无效的文件标识符。使用 fopen 生成有效的文件标识符。”

我可以知道这个错误的可能原因是什么吗?我对 Matlab 很陌生。请帮我。非常感谢

如果我不应该发布整体功能,我很抱歉。但恐怕我提供的信息还不够。该函数的总体命令是:

function  gau_hmm_init_train(traininglist_filename,model_filename,MODEL_NO,STATE_NO, dim )
if nargin == 0
    traininglist_filename='training_list.mat' ;
    model_filename='models.mat';
    MODEL_NO=11;
    STATE_NO=4;
    dim=12;
end
MIN_SELF_TRANSITION_COUNT=0;
load(traininglist_filename,'list');
% allocate mean, var vectors, transition prob. for the of models
mean_vec_i_m=zeros(dim,STATE_NO,MODEL_NO);
var_vec_i_m=zeros(dim,STATE_NO,MODEL_NO);
A_i_m=zeros(STATE_NO,MODEL_NO);
vector_sums_i_m=zeros(dim,STATE_NO,MODEL_NO);
var_vec_sums_i_m=zeros(dim,STATE_NO,MODEL_NO);
fr_no_i_m=zeros(STATE_NO,MODEL_NO);
self_tr_fr_no_i_m=zeros(STATE_NO,MODEL_NO);
utterance_no=size(list,1);
total_fr_no=0;
for k=1:utterance_no
    filename=list{k,2};
    m=list{k,1}; % word ID
    fid=fopen(filename,'r');
    fseek(fid, 12, 'bof'); % skip the 12-byte HTK header
    %fopen(fid, 12, 'bof'); % skip the 12-byte HTK header
    c=fread(fid,'float','b');
    fclose(fid);
    fr_no=length(c)/dim;
    total_fr_no=total_fr_no+fr_no;
    c=reshape(c,dim,fr_no);

    for i=1:STATE_NO
        begin_fr=round(  fr_no*(i-1) /STATE_NO)+1;
        end_fr=round( fr_no*i /STATE_NO);
        seg_length=end_fr-begin_fr+1;
        vector_sums_i_m(:,i,m) = vector_sums_i_m(:,i,m) + sum(c(:,begin_fr:end_fr),2);
        var_vec_sums_i_m(:,i,m) = var_vec_sums_i_m(:,i,m) +  sum( c(:,begin_fr:end_fr).*c(:,begin_fr:end_fr) , 2);
        fr_no_i_m(i,m)=fr_no_i_m(i,m)+seg_length;
        self_tr_fr_no_i_m(i,m)= self_tr_fr_no_i_m(i,m) + seg_length-1;
    end %for s=1:STATE_NO
end % for k=1:utterance_no
for m=1:MODEL_NO
    for i=1:STATE_NO
        mean_vec_i_m(:,i,m) = vector_sums_i_m(:,i,m) / fr_no_i_m(i,m);
        var_vec_i_m(:,i,m) = var_vec_sums_i_m(:,i,m) / fr_no_i_m(i,m);
        A_i_m(i,m)=(self_tr_fr_no_i_m(i,m)+MIN_SELF_TRANSITION_COUNT)/(fr_no_i_m(i,m)+2*MIN_SELF_TRANSITION_COUNT);
    end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                   tying of cov. matrices
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
overall_var_vec=sum(sum(var_vec_sums_i_m(:,:,:),3 ),2)/sum(sum(fr_no_i_m,2 ),1);
for m=1:MODEL_NO
    for i=1:STATE_NO
        var_vec_i_m(:,i,m)=overall_var_vec;
    end
end
%%%%%%%%%%%%%%%%            end of cov. matrices tying
save(model_filename, 'mean_vec_i_m', 'var_vec_i_m', 'A_i_m');
fprintf('init. train complete \n');***
4

2 回答 2

1

听起来像行fid=fopen(filename, 'r')。该文件名来自从list文件加载的变量traininglist_filename,因此您应该检查这些文件是否存在。如果你要传递它,traininglist_filename你应该在 MATLAB 中加载这个文件并查看列表的内容;否则它将加载默认值'training_list.mat',因此您应该在那里查看以确保所有文件名都有效。也许你错过了一个文件?

于 2013-04-21T08:10:27.923 回答
-1

要继续@Wakjah 的回复,training_list.mat您正在使用的代码的引用路径中缺少该文件,因为它是在 MATLAB 默认路径下自动创建的。因此,只需将“当前文件夹”的路径更改为您打开当前代码的位置,它应该可以工作。

于 2016-06-03T07:11:35.840 回答