2013-04-21 106 views
0

我同時在MatlabFSEEK錯誤,同時運行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');*** 

回答

1

聽起來就像是線fid=fopen(filename, 'r')。這個文件名來自list變量,它是從文件traininglist_filename加載的,所以你應該檢查這些文件是否存在。如果你通過它traininglist_filename你應該加載這個文件在MATLAB中,看看列表的內容;否則它會加載默認'training_list.mat',所以你應該看看那裏以確保所有的文件名都是有效的。也許你錯過了一個文件?

+0

非常感謝Wakjah的回答。請問,如果給出的數據集是.zip,我應該先提取它?如果這個問題聽起來很愚蠢,我很抱歉。非常感謝 – user2301196 2013-04-21 09:43:44

+0

對不起,可能是我應該通過發佈命令來提出更清晰的問題。 list_filename ='training_list.mat'; dir1 ='mfcc_e_d_a/isolated_digits_ti_train_endpt'; dir2 = {'MAN','WOMAN'}; dir3 = {{'AE','AJ','AL','AW','BD','CB','CF','CR','DL','DN','EH',' EL','FC','FD','}, 是否意味着我應該爲dir1,dir2和dir3創建3個文件夾?謝謝 – user2301196 2013-04-21 10:01:01

-1

要繼續@Wakjah的回覆,training_list.mat文件在您使用的代碼中從參考路徑丟失,因爲它是在MATLAB默認路徑中自動創建的。因此,只需將「當前文件夾」中的路徑更改爲打開當前代碼的位置,即可使用。

+1

雖然這是一個答案,你可以擴展它嗎?在這裏閱讀更多關於如何給出良好答案的信息http://stackoverflow.com/help/how-to-answer – 2016-06-03 07:12:39