【问题标题】:Output argument "am" (and maybe others) not assigned during call to调用期间未分配输出参数“am”(可能还有其他参数)
【发布时间】: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

标签: matlab


【解决方案1】:

问题可能出在

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

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

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

【讨论】:

    猜你喜欢
    • 2013-10-04
    • 1970-01-01
    • 1970-01-01
    • 2017-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多