Class : Error while assigning variables in constructor

1 vue (au cours des 30 derniers jours)
Ankit Singh
Ankit Singh le 24 Fév 2022
Modifié(e) : per isakson le 25 Fév 2022
I am getting error while assigning variables in classes :
properties
% The antenna object from the phased array toolbox
ant = [];
% Frequency in Hz
fc = 0;
end
methods
function myobj = ElemWithAxes(fc, ant)
% Constructor
% Inputs: fc is the carrier frequency in Hz and ant is
% an antenna compatible with the phased array toolbox. It must
% support the ant.pattern() method.
% TODO: Assign fc and ant to the class variables
myobj.fc = fc;
myobj.ant = ant;
end
I get the following :
Not enough input arguments.
Error in ElemWithAxes (line 40)
myobj.fc = fc;
Where does the problem lie ?

Réponses (1)

per isakson
per isakson le 25 Fév 2022
Modifié(e) : per isakson le 25 Fév 2022
How did you call the constructor?
I added a few line to make your code a syntactically correct class. And tested the constructor.
ewa = ElemWithAxes(1,2)
ewa =
ElemWithAxes with properties: ant: 2 fc: 1
ewa = ElemWithAxes()
Not enough input arguments.

Error in ElemWithAxes (line 17)
myobj.fc = fc;
Did you call the constructor without input argument values?

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by