MATLAB: Object Oriented Programming – Leaving properties from objects empty.

object oriented programming - empty arguments - constructor

Hi everybody! I am writing the following code:
classdef Value0_1
properties
Price
Earnings
ddd
BookValue
P_E_Calc
P_B_Calc
end
methods
function PE=Value0_1(price,earnings,Ddd)
if nargin <2
PE.Price=price;
PE.Earnings=earnings;
PE.ddd=Ddd;
end
end
end
end
Now, I would like to create an object by typing in the command Window PriceEarnings=Value0.1(555,555,~). the following error comes: Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
–> How can I leave the argument Ddd empty?

Best Answer

The call should look like PriceEarnings=Value0_1(555,555) and the code for the constructor should look like,
function PE=Value0_1(price,earnings,Ddd)
if nargin >=1
PE.Price=price;
end
if nargin>=2
PE.Earnings=earnings;
end
if nargin>=3
PE.ddd=Ddd;
end
end