调用期间未分配输出参数“am”(可能还有其他参数)

Posted

技术标签:

【中文标题】调用期间未分配输出参数“am”(可能还有其他参数)【英文标题】:Output argument "am" (and maybe others) not assigned during call to 【发布时间】:2015-06-14 09:51:02 【问题描述】:

我试图在我的 m 文件中使用这个函数,但我得到一个错误(有问题提到)。一切似乎都是正确的,并且在我的 m 文件中定义了 a、b 和 c。有什么想法吗? 错误: Error in modal2 (line 8) [v,an]=eig(a); Output argument "am" (and maybe others) not assigned during call to "C:\Users\Cena\Desktop\Thesis\My Codes\SMC\modal2.m>modal2".

function [r,am,bm,cm] = modal2(a,b,c)
% this function determines the modal representation 2(am,bm,cm)
%given a generic state-space representation (a,b,c)
%and the transformation r to the modal representation
%such that am=inv(r)*a*r, bm=inv(r)*b and cm=c*r

%transformation to complex-diagonal form:
[v,an]=eig(a);
bn=inv(v)*b;
cn=c*v;

%transformation to modal form 2:
i = find(imag(diag(an))');
index = i(1:2:length(i));
   j=sqrt(-1);
   t = eye(length(an));

if isempty(index)
   am=an;bm=bn;cm=cn;

else
   for i=index
        t(i:i+1,i:i+1)=[j 1;-j 1];
end
%Modal transformation
    r=v*t;
end

【问题讨论】:

您是否创建了自己的eig.m 来遮盖内置的? which eig 返回什么? 内置 (D:\Program Files\MATLAB\R2012a\toolbox\matlab\matfun\@single\eig) % 单一方法 现在重新阅读错误信息我真的很困惑。输出参数称为an,但错误说明了am。一开始没看出差别。不知道这里发生了什么。 我没有创建 ant 'eig.m' 文件@Daniel 【参考方案1】:

问题可能出在

if isempty(index)
   am=an;bm=bn;cm=cn;

只有在条件通过时才会对这些变量进行赋值。如果不是,则没有分配。

如果它们将成为输出参数,则需要修改代码以在所有条件下分配给这些变量。

【讨论】:

以上是关于调用期间未分配输出参数“am”(可能还有其他参数)的主要内容,如果未能解决你的问题,请参考以下文章

调用期间未分配输出参数:Matlab

错误:调用期间未分配输出参数

在将 std::string 分配给模板参数期间编译时出错

C#使用输出变量调用存储过程时出错,未提供参数

函数参数的内存分配

GDB:如何在调试期间调用具有修改参数的函数