Sina
Sina

Reputation: 183

Output argument "am" (and maybe others) not assigned during call to

I am trying to use this function in my m file but I get an error(mentioned in question). Everything seems correct and a, b and c are defined in my m file. Any thoughts? Error: 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

Upvotes: 1

Views: 1574

Answers (1)

paisanco
paisanco

Reputation: 4164

The problem is likely in

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

The assignment to those variables is only being done if the conditional passes. If it doesn't , there is no assignment.

You need to modify your code to assign to those variables under all conditions if they are going to be output arguments.

Upvotes: 1

Related Questions