Reputation: 11
I'm trying to define a class whose static method re-use already defined static method at the same class.
classdef DesignOpt
methods (Static)
ToMatrix(vector)
Phi2G(Phi)
end
end
function matrix = ToMatrix(vector)
if length(vector) == 6
matrix = [0, -vector(3), vector(2), vector(4);
vector(3), 0, -vector(1), vector(5);
-vector(2), vector(1), 0, vector(6);
0, 0, 0, 0];
return
elseif length(vector) == 3
matrix = [ 0, -vector(3), vector(2);
vector(3), 0, -vector(1);
-vector(2), vector(1), 0];
return
else
matrix = nan(4, 4);
error(['<ToMatrix> ftn : vector.rows() = ' num2str(size(vector,1))])
end
end
function G = Phi2G(Phi)
if(size(Phi,1) ~= 10)
error(['ERROR: Wrong input size for PhiToG(): Phi.rows() = ' num2str(size(Phi,1))])
G = nan(6,6);
return
end
G = zeros(6,6);
m_Eye = Phi(1) * eye(3);
h_bracket = DesignOpt.ToMatrix(Phi(2:4));
I_moment = [Phi(5), Phi(8), Phi(10);
Phi(8), Phi(6), Phi(9);
Phi(10), Phi(9), Phi(7)];
G(1:3,1:3) = I_moment;
G(1:3,4:6) = h_bracket;
G(4:6,1:3) = h_bracket';
G(4:6,4:6) = m_Eye;
end
I want to use ToMatrix method inside Phi2G, but
Error using: DesignOpt.ToMatrix
Too many output arguments.
Error: DesignOpt.Phi2G (line 12)
h_bracket = DesignOpt.ToMatrix(Phi(2:4));
How can I fix it??
Upvotes: 1
Views: 157
Reputation: 25140
You need to declare in your classdef
that the method ToMatrix
has an output argument. Here's a working example:
% @TestClass/TestClass.m:
classdef TestClass
methods (Static)
fcn1()
out = fcn2() % Note: declare output argument(s)
end
end
% @TestClass/fcn1.m
function fcn1()
disp(TestClass.fcn2());
end
% @TestClass/fcn2.m
function out = fcn2()
out = 7;
end
Upvotes: 1