594wolfo 发表于 2010-6-1 17:04:29

子函数问题(Output argument "g" (and maybe others) not assigned )

本帖最后由 594wolfo 于 2010-6-2 09:30 编辑

function N = pe(M, varargin)
...
...

function Per(flag)    %1
    ...   
      N= sy(fa);
      return;
    elseif ...
    elseif ...
    elseif ...
end
end

function g= sy(A)   %2
      uniqued= unique(A, 'rows');
      g= NaN;
      = size(uniqued, 1);
      for i=1:nr
          try0= -uniqued(i, :);
          test= find((ismember(uniqued, try0,'rows'))');
          if isempty(test)
            return
          else
            uniqued(test,:)=-uniqued(test,:);
          end
          %disp(uniqued);
      end      
      g= unique(uniqued, 'rows');
end??? Output argument "g" (and maybe others) not assigned during call to "C:\Documents and Settings\..\MATLAB\pe.m>sy".

很怪异
g定义了 也分配了 怎么会报错呢
多谢



messenger 发表于 2010-6-1 17:21:58

把第30行的end命令去掉试试,Matlab函数返回用不着end

594wolfo 发表于 2010-6-1 17:41:19

本帖最后由 594wolfo 于 2010-6-1 17:43 编辑

多谢建议
可是直接报错
??? Error: File: pe.m Line: 96 Column: 1
The function "pe" was closed
with an 'end', but at least one other function definition was not.
To avoid confusion when using nested functions,
it is illegal to use both conventions in the same file.

我的是2010a
对了 其实加上end时 如果comment掉后面的那个 g=uniqued(29行), 可以直接返回 nan
而且27行的那个 disp也可以正确打印出值,可是为什么到后面就挂掉了。。。
狂晕

messenger 发表于 2010-6-1 18:00:54

感觉这个错误是你的变量g,在循环中没有被赋值,而函数在被调用后试图返回g的值而出错。

建议你将for...end这个循环注释掉以后,再看看是否出错。

594wolfo 发表于 2010-6-2 09:07:02

谢谢了
不是for的问题
是 那个 return的问题

把22-25行 修改成
          if ~isempty(test)
            uniqued(test,:)= -uniqued(test,:);
就好使了
页: [1]
查看完整版本: 子函数问题(Output argument "g" (and maybe others) not assigned )