无法使用" load"读取文件在matlab中

时间:2014-10-08 18:15:38

标签: matlab

我无法执行以下代码。当我运行代码时,它显示我:

Error using load
Unable to read file 'motionDB.mat': no such file or directory.
Error in:  else  load ('motionDB.mat');

然而,当我删除第二个“if循环”时,它正常运行。

我的代码:

  user_filter='gaussian';  
  if(strcmpi(user_filter,'gaussian')==1)
         h = fspecial('gaussian', [3 3], 1);% gauss filter
         if ~exist('gaussianDB.mat')
              createHistDB( num_bins,Dir,srcFiles,filter,h,num_red_bins,num_green_bins,num_blue_bins,B );
         end
         else  load('gaussianDB.mat');
    end

 if(strcmpi(user_filter,'motion')==1)% motion filter
      h=fspecial('motion', 20, 45);
      if ~exist('motionDB.mat')
              createHistDB( num_bins,Dir,srcFiles,filter,h,num_red_bins,num_green_bins,num_blue_bins, B );
      end
       else  load('motionDB.mat');
    end

有什么想法吗?提前谢谢。

1 个答案:

答案 0 :(得分:0)

我认为您已经混淆了代码中的elseend语句。而不是:

if(strcmpi(user_filter,'gaussian')==1)
     h = fspecial('gaussian', [3 3], 1);% gauss filter
     if ~exist('gaussianDB.mat')
          createHistDB( num_bins,Dir,srcFiles,filter,h,num_red_bins,num_green_bins,num_blue_bins,B );
     end
     else  load('gaussianDB.mat');
end

尝试:

if(strcmpi(user_filter,'gaussian')==1)
     h = fspecial('gaussian', [3 3], 1);% gauss filter
     if ~exist('gaussianDB.mat')
          createHistDB( num_bins,Dir,srcFiles,filter,h,num_red_bins,num_green_bins,num_blue_bins,B );
     else  
          load('gaussianDB.mat');
     end
end