Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Matlab中纠正这个错误_Matlab - Fatal编程技术网

如何在Matlab中纠正这个错误

如何在Matlab中纠正这个错误,matlab,Matlab,我已经定制了下面的部分功能功能\u select.m以使用我自己生成的掩码全脑掩码\u 1,全脑掩码\u 2,…,全脑掩码\u 10进入主题 function [subj] = feature_select(subj,data_patin,regsname,selsgroup,varargin) % No-peeking feature selection % % [SUBJ] = FEATURE_SELECT(SUBJ,DATA_PATIN,REGSNAME,SELSGROUP,...) %

我已经定制了下面的部分功能
功能\u select.m
以使用我自己生成的掩码
全脑掩码\u 1
全脑掩码\u 2
,…,
全脑掩码\u 10
进入
主题

function [subj] = feature_select(subj,data_patin,regsname,selsgroup,varargin)

% No-peeking feature selection
%
% [SUBJ] = FEATURE_SELECT(SUBJ,DATA_PATIN,REGSNAME,SELSGROUP,...)
%
% Calls a statmap generation function multiple times, using
% a different selector each time. This creates a group of
% statmaps, which are then thresholded to create a group of
% boolean masks, ready for use in no-peeking
% cross-validation classification.
%
% Adds the following objects:
% - pattern group of statmaps called NEW_MAP_PATNAME
% - mask group based on the statmaps called
%   sprintf('%s%i',NEW_MASKSTEM,THRESH)
%
% DATA_PATIN should be the name of the pattern object that
% contains voxel (or other feature) values that you want to
% create a mask of. If DATA_PATIN is a group_name, then this
% will use a different member of the group for each
% iteration.
%
% REGSNAME should be a binary nConds x nTimepoints 1-of-n matrix
%
% SELSGROUP should be the name of a selectors group, such as
% created by create_xvalid_indices
%
% For each iteration: call the ANOVA on the DATA_PATIN data,
% which will produce a statmap, employing only the TRs
% labelled with a 1 in the selector for that iteration
%
% NEW_MAP_PATNAME (optional, default = DATA_PATIN +
% STRIPPED_NAME). The name of the new statmap pattern group
% to be created. By default, this will be 'anova' if
% STATMAP_FUNCT = 'statmap_anova' etc.
%
% NEW_MASKSTEM (optional, default = DATA_PATIN +
% 'anovathresh'). The name of the new thresholded boolean
% mask group to be created from the ANOVA statmap. You'll
% need to create multiple mask groups if you want to try out
% multiple thresholds, so adding the threshold to the name
% is a good idea
%
% THRESH (optional, default = 0.05). Voxels that don't meet
% this criterion value don't get included in the boolean
% mask that gets created from the ANOVA statmap. If THRESH =
% [], the thresholding doesn't get run
%
% STATMAP_FUNCT (optional, default = 'statmap_anova'). Feed
% in a function name and this will create a function handle
% to that and use it to create the statmaps instead of
% statmap_anova
%
% STATMAP_ARG (optional, default = []). If you're using an
% alternative voxel selection method, you can feed it a
% single argument through this
%
% Need to implement a THRESH_TYPE argument (for p vs F
% values), which would also set the toggle differently xxx
%
% e.g. subj = feature_select( ...
%         subj,'epi_z','conds','runs_nmo_xvalid','thresh',0.001)

% License:
%=====================================================================
%
% This is part of the Princeton MVPA toolbox, released under
% the GPL. See http://www.csbmb.princeton.edu/mvpa for more
% information.
% 
% The Princeton MVPA toolbox is available free and
% unsupported to those who might find it useful. We do not
% take any responsibility whatsoever for any problems that
% you have related to the use of the MVPA toolbox.
%
% ======================================================================


defaults.new_map_patname = '';
defaults.new_maskstem = sprintf('%s_thresh',data_patin);
defaults.thresh = 0.05;
defaults.statmap_funct = 'statmap_anova';
defaults.statmap_arg = struct([]);
args = propval(varargin,defaults);

if isempty(args.new_map_patname)
  % get the name of the function being run, e.g. 'statmap_anova' -> 'anova'
  stripped_name = strrep(args.statmap_funct,'statmap_','');
  args.new_map_patname = sprintf('%s_%s',data_patin,stripped_name);
end

% append the thresh to the end of the name
args.new_maskstem = sprintf( ...
    '%s%s',args.new_maskstem,num2str(args.thresh));

% Find the selectors within the specified group
selnames = find_group(subj,'selector',selsgroup);
nIterations = length(selnames);

[data_patnames isgroup] = find_group_single(subj,'pattern',data_patin,'repmat_times',nIterations);

if length(data_patnames) ~= length(selnames)
  error('Different number of patterns and selectors');
end

if nIterations == 0
  error('No selectors in %s group',selsgroup);
end

% % this warning used to be here to remind people of the
% % existence of peek_feature_select, but since there are good
% % reasons why one might want to have just one selector
% % without using peek_feature_select, i took it out
% if nIterations == 1
%   warning('You''re only calling the anova once because you have one selector - use peek_feature_select instead?');
% end

if ~ischar(args.statmap_funct)
  error('The statmap function name has to be a string');
end

disp( sprintf('Starting %i %s iterations',nIterations,args.statmap_funct) );

for n=1:nIterations
  fprintf('  %i',n);

  % Get the pattern for this iteration
  cur_data_patname = data_patnames{n};

  % Get the selector name for this iteration
  cur_selname = selnames{n};

  % Name the new statmap pattern and thresholded mask that will be created
  cur_maskname = sprintf('%s_%i',args.new_maskstem,n);
  cur_map_patname = sprintf('%s_%i',args.new_map_patname,n);

  % if a pattern with the same name already exists, it
  % will trigger an error later in init_object, but we
  % want to catch it here to save running the entire
  % statmap first
  if exist_object(subj,'pattern',cur_map_patname)
    error('A pattern called %s already exists',cur_map_patname);
  end

  if ~isempty(args.statmap_arg) && ~isstruct(args.statmap_arg)
    warning('Statmap_arg is supposed to be a struct');
  end

  % Add the current iteration number to the extra_arg, just in case
  % it's useful
  args.statmap_arg(1).cur_iteration = n;

  % Create a handle for the statmap function handle and then run it
  % to generate the statmaps
  statmap_fh = str2func(args.statmap_funct);
  subj = statmap_fh(subj,cur_data_patname,regsname,cur_selname,cur_map_patname,args.statmap_arg);
  subj = set_objfield(subj,'pattern',cur_map_patname,'group_name',args.new_map_patname);

  if ~isempty(args.thresh)
    % Now, create a new thresholded binary mask from the p-values
    % statmap pattern returned by the anova
    subj = create_thresh_mask(subj,cur_map_patname,cur_maskname,args.thresh);
    subj = set_objfield(subj,'mask',cur_maskname,'group_name',args.new_maskstem);
  end

end % i nIterations

disp(' ');
disp( sprintf('Pattern statmap group ''%s'' and mask group ''%s'' created by feature_select', ...
          args.new_map_patname,args.new_maskstem) );
这是上面的一部分功能,我已经适应使用我自己的面具:

dirIn_Mask = ['/D disk/my_fold/My_generated_Mask'];

data_patin = subj.patterns{1,2}.name;  

defaults.new_maskstem = sprintf(‘whole_brain_mask’); 

defaults.statmap_arg = struct([]);

args = propval(varargin,defaults);

args.new_maskstem = sprintf( '%s',args.new_maskstem );

for n = 1:1:10

fprintf('  %i', n );

inputFile_mask = ['whole_brain_mask_',num2str(n)];

load(fullfile(dirIn_Mask,inputFile_mask)); 

    cur_maskname = sprintf('%s_%i',args.new_maskstem,n );

    subj.masks{1,(runID+1)}.mat = whole_brain_new_1; 


    subj = set_objfield(subj,'mask',cur_maskname,'group_name',new_maskstem);
end
Attempt to execute SCRIPT varargin as a function:
C:\D disk\MATLAB\R2014a\toolbox\matlab\lang\varargin.m
Error in MVPA (line 89)
args = propval(varargin,defaults);
这就是我得到的错误:

dirIn_Mask = ['/D disk/my_fold/My_generated_Mask'];

data_patin = subj.patterns{1,2}.name;  

defaults.new_maskstem = sprintf(‘whole_brain_mask’); 

defaults.statmap_arg = struct([]);

args = propval(varargin,defaults);

args.new_maskstem = sprintf( '%s',args.new_maskstem );

for n = 1:1:10

fprintf('  %i', n );

inputFile_mask = ['whole_brain_mask_',num2str(n)];

load(fullfile(dirIn_Mask,inputFile_mask)); 

    cur_maskname = sprintf('%s_%i',args.new_maskstem,n );

    subj.masks{1,(runID+1)}.mat = whole_brain_new_1; 


    subj = set_objfield(subj,'mask',cur_maskname,'group_name',new_maskstem);
end
Attempt to execute SCRIPT varargin as a function:
C:\D disk\MATLAB\R2014a\toolbox\matlab\lang\varargin.m
Error in MVPA (line 89)
args = propval(varargin,defaults);

有人能帮我解决这个问题吗

从代码中删除
varargin
varargin
是一个特殊的关键字,只有在将代码作为函数运行时才可用
varargin
允许在函数中输入不同数量的输入。这些输入被散列到一个单元格数组中

因为这是一个脚本文件,所以该变量不存在。从您收到的MATLAB错误中也可以看出这一点。FWIW、MATLAB错误消息非常详细。很难曲解或误解他们想说的话

因此,请执行以下操作:

args = propval(defaults);
如果这不起作用,那么我不确定
propval
是如何接收输入的,但也许可以用放入空单元格数组来愚弄它:

args = propval(cell(1,1), defaults);

由于函数
propval
依赖于数量可变的输入,因此它应该处理
varargin
不存在的情况,因此我们可以通过使用空单元格数组模拟
varargin
没有附加参数。

您使用
varargin
作为
propval
的参数,但是
varargin
在代码中的任何地方都没有定义。在这种情况下,
varargin
回滚到Matlab脚本
varargin
。因此,解释器假定您希望将其作为一个函数运行,该函数将值返回到
propval
,并且假定脚本不应该返回值,则会收到错误消息


作为旁注:
varargin
通常被设置为函数的最后一个参数,以允许程序员声明具有可变参数数的函数。

我正在立即尝试。当我执行“args=propval(默认)”时,错误是使用propval时出错(第112行)输入参数不足。分类错误(第89行)args=propval(默认值);;当我执行“args=propval(单元格(1,1),默认值)”时,错误是:错误使用propval(第109行)属性值对必须是单元格数组或结构。分类错误(第89行)args=propval(单元格(1,1),默认值);我不知道这个函数是什么样子,所以我不能再帮你了。很抱歉祝你好运如果我不使用Propval,如何修改我的代码以达到我的目的?谢谢你的回答,我正在设法解决它。如果你知道怎么修理,请告诉我!什么是
propval
作为输入?为什么MVPA中没有定义
varargin
,而您仍将其作为参数传递给
propval
?我只想使用函数的一部分将生成的掩码写入“subj”。取出
propval
默认值…
行,并包括
args.new_maskstem=sprintf('whole_brain_mask')
args.statmap_arg=struct([])
args.new\u maskstem=sprintf(“%s”,args.new\u maskstem)我正在立即尝试。