I'm having problems with the class constructor for my CoaxLine
class. I pass it all the arguments it needs, but when I create an object in another program, I get the error:
Error using length Not enough input arguments.
Error in CoaxLine (line 23) function obj = CoaxLine(pow,len,h,freq,x1,x2,y1,y2,dir,split)
Error in Test2 (line 38) coax1 = CoaxLine(3.9,100,4.75,1800,10,110,10,10,0,1);
I got this same error with length even when I removed all the argument requirements for the constructor, and created the object with no inputs. This is my first time building a class in MATLAB, so it is likely that I missed something silly. I appreciate the help.
Here is the code for CoaxLine
:
classdef CoaxLine
%UNTITLED2 Summary of this class goes here
% Detailed explanation goes here
properties
%Default values
PA = 3.9;
orientation = 0; %0 for East-West, 1 for North-South
splitter = 1; %0 for left side, 1 for right side
length = 90;
frequency = 1800; %in MHz
height = 4.75;
Ce = 8.77; %Hardcoded for now
Lint = .13; %Hardcoded
nearFieldLength = 2*(length^2)/((3.0*10^8)/(frequency*10^6));
X1 = 10; %Will be points in the simulation axis
X2 = 110;
Y1 = 10;
Y2 = 10;
%loss = 10;
end
methods
function obj = CoaxLine(pow,len,h,freq,x1,x2,y1,y2,dir,split)
%if nargin > 0
obj.PA = pow;
obj.length = len;
obj.height = h;
obj.frequency = freq;
obj.X1 = x1;
obj.X2 = x2;
obj.Y1 = y1;
obj.Y2 = y2;
obj.orientation = dir;
obj.splitter = split;
%end
end
function r = contribution(px,py)
if(obj.orientation == 0)
if(obj.splitter)
if(abs(py - obj.Y1) <= obj.nearFieldLength && px > obj.X1 && px < obj.X2)
H = abs(py - obj.Y1);
x = px - obj.X1;
r = NearFieldPropagation(obj.PA,obj.length,obj.frequency,H,obj.height,obj.Ce,obj.Lint,x);
end
else
if(abs(py - obj.Y1) <= obj.nearFieldLength && px < obj.X1 && px > obj.X2)
H = abs(py - obj.Y1);
x = obj.X1 - px;
r = NearFieldPropagation(obj.PA,obj.length,obj.frequency,H,obj.height,obj.Ce,obj.Lint,x);
end
end
%else
end
end
end
end
The error stems from this line:
nearFieldLength = 2*(length^2)/((3.0*10^8)/(frequency*10^6));
MATLAB thinks that you're trying to call the function length
. That requires an argument whose length will be returned.
The use of frequency
will give you headaches too. To properly handle this kind of properties
you should declare your nearFieldLength
as Dependent
: http://www.mathworks.com/help/matlab/matlab_oop/access-methods-for-dependent-properties.html and then write a getter for it that will calculate its value on the fly.
Also, as excaza noted, you'll have further errors because you don't declare obj
as argument in contribution
.
This is my idea on how the code should look like:
classdef CoaxLine
properties
PA = 3.9;
orientation = 0;
splitter = 1;
length = 90;
frequency = 1800;
height = 4.75;
Lint = .13;
X1 = 10;
X2 = 110;
Y1 = 10;
Y2 = 10;
end;
properties(Dependent, SetAccess=private)
Ce;
nearFieldLength;
end;
methods
%//Constructor
function obj = CoaxLine(pow,len,h,freq,x1,x2,y1,y2,dir,split)
if nargin > 0
obj.PA = pow;
obj.length = len;
obj.height = h;
obj.frequency = freq;
obj.X1 = x1;
obj.X2 = x2;
obj.Y1 = y1;
obj.Y2 = y2;
obj.orientation = dir;
obj.splitter = split;
end;
end;
%//Getters for dependent properties
function val = get.Ce(obj) %#ok<MANU>
val = 8.77; %//this can be changed later
end;
function val = get.nearFieldLength(obj)
val = 2*(obj.length^2)/(3E8/(obj.frequency*1E6));
end;
%//Normal methods
function r = contribution(obj, px, py)
r = []; % some default value
if obj.orientation == 0
if obj.splitter
if abs(py - obj.Y1) <= obj.nearFieldLength ...
&& px > obj.X1 ...
&& px < obj.X2
H = abs(py - obj.Y1);
x = px - obj.X1;
r = NearFieldPropagation(obj.PA,obj.length,obj.frequency,H,obj.height,obj.Ce,obj.Lint,x);
end;
else
if abs(py - obj.Y1) <= obj.nearFieldLength ...
&& px < obj.X1 ...
&& px > obj.X2
H = abs(py - obj.Y1);
x = px - obj.X1;
r = NearFieldPropagation(obj.PA,obj.length,obj.frequency,H,obj.height,obj.Ce,obj.Lint,x);
end;
end;
end;
end;
end;
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.