Arxas
Arxas

Reputation: 241

Matlab class function - getting returned value

In my project I use two classes - row and triangle. Class row in its functions creates triangle class objects:

classdef row < handle

% some parameters here

methods

% constructor and some other functions here

function [T1 T2] = createFoR(obj, hT, Alpha, Beta, DeltaAlpha, DeltaBeta)
         % creating P1 matrix (irrelevant, its 100% correct)
         T1 = triangle(P1);
         % creating P2 matrix (irrelevant, its 100% correct)
         T2 = triangle(P2);
end

end

When I'm calling this row class function like this:

[T1 T2] = Row1.createFoR(T(1,1), Alpha, Beta, DeltaAlpha, DeltaBeta);

or like this:

[T(2,1) T2] = Row1.createFoR(T(1,1), Alpha, Beta, DeltaAlpha, DeltaBeta);

everything works perfectly fine. But when I attempt to assign both returned triangle objects to array cells like this:

[T(2,1) T(2,2)] = Row1.createFoR(T(1,1), Alpha, Beta, DeltaAlpha, DeltaBeta);

I get this error:

Error using triangle (line 10)
Not enough input arguments.

Error in test (line 20)
[T(2,1) T(2,2)] = Row1.createFoR(T(1,1), Alpha, Beta, DeltaAlpha, DeltaBeta);

May I kindly ask you to explain me what I'm doing wrong?

Upvotes: 2

Views: 2335

Answers (1)

ccook
ccook

Reputation: 5959

It looks like T is an object, where T(double,double) is a function/constructor. So in the case you point out

[T(2,1) T(2,2)] = Row1.createFoR(T(1,1), Alpha, Beta, DeltaAlpha, DeltaBeta);

You are actually calling T(double, double) three times, where the error occurs specifically in T(2,2), (where the code is 100% correct?).

Updated from comment

What is odd is the input argument error in triangle line 10. Could the problem be in P1, P2?

You could also try the following - but its guesswork without something I can run/reproduce the problem (the error is in code not listed?)

[T1 T2] = Row1.createFoR(T(1,1), Alpha, Beta, DeltaAlpha, DeltaBeta);
T(2,1:2) = [T1, T2];

Answer:

Another thought is that when T(2,2) is filled its trying to construct T(1,2) with no arguments?

Upvotes: 2

Related Questions