Not enough Input Argument error

% I am certain that the two 'Test' variables are not empty or invalid. I am trying to call a function CountyryData using 2 input variables!
app.Test = string(cellfun(@(Data) Data(1), app.Data(61,3)));
app.Test2=app.C(61,1);
app.CumulativeCases=CountryData(app.Test2,app.Test);
%Calling this Function - that requires 2 input variables. However the Not enough Arguments error keeps coming up..
classdef CountryData < Countries
properties
CCC
Temp
end
methods
function obj = CountryData(name1,data1)
obj.Temp=name1;
obj.CCC=data1;
end
end
end

3 Kommentare

Geoff Hayes
Geoff Hayes am 16 Sep. 2021
Padmakar - perhaps the issue is with the Countries class? Please copy and paste the full error messag eto this question as that might reveal where the error is. Also, what are the values for app.Test2 and app.Test?
function DataLoading(app)
load 'covid_data2.mat' covid_data;
[app.r,app.col]=size(covid_data);
for i=2:app.r
j=i-1;
CountryList(j)=string(covid_data(i,1));
end
app.Data=covid_data(2:end,:);
app.Dates=covid_data(1,3:app.col);
[app.C,~,IC]=unique(CountryList,'stable');
app.C=app.C';
Y = hist(IC,unique(IC)); % Determine frequency of repeated Country Names in Column 1
Y=Y';
j=0;
m=0;
n=1;
for i=1:length(app.C)
j=Y(i,1);
if j ==1
k=m+1;
app.Country(i)=Countries(app.C(i,1),app.Data(k:k,2));
m=k;
elseif j > 1
n=m+j;
m=m+1;
app.Country(i)=Countries(app.C(i,1),app.Data(m:n,2));
m=n;
end
end
app.CountryListBox.Items=["All Countries", app.Country.CountryNameList];
app.CountryListBox.Value= "All Countries";
app.RegionListBox.Items="All";
app.Test = cellfun(@(Data) Data(1), app.Data(61,3));
app.Test2=app.C(61,1);
app.CumulativeCases=CountryData(app.Test,app.Test2);
PADMAKAR
PADMAKAR am 18 Sep. 2021
I have attached 2 classdeg files. Countries is a superclass and CountryData is a subClass.
I am just testing the CumulativeCases Object using some Test data randomly created.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Cris LaPierre
Cris LaPierre am 16 Sep. 2021

0 Stimmen

CountryData is a class. I believe you need to create an instance of your object and then use that when calling your method. See this answer. See this documentation page.
Something like this.
c = CountryData;
CountryData(c,app.Test2,app.Test)

3 Kommentare

PADMAKAR
PADMAKAR am 18 Sep. 2021
%As suggested, I created a simple code - No success. Also made CountryData a superclass. No %Success.
app.CumulativeCases=CountryData;
app.CumulativeCases(1).Country=app.C(1,1);
app.CumulativeCases(1).Dates=app.Dates(1,3);
app.CumulativeCases(1).CumCases=cellfun(@(Data) Data(1), app.Data(1,3));
%Not sure what is casuing Not enough inputs error. Appreciate your insight..
classdef CountryData
properties
Country
Date
CumCases
end
methods
function obj1 = CountryData(country,date,cumcases)
%obj1@Countries(name,state);
obj1.Country=country;
obj1.Date=date;
obj1.CumCases=cumcases;
end
end
end
Your class is slightly different from the one I pointed you to. The main difference is that your function has the same name as your class (CountryData), making is a constructor method. From the page I pointed you to:
  • The constructor method has the same name as the class and returns an initialized object of the class.
Your function has 3 inputs, so when you create your class instance, you must do so using 3 inputs.
app.Data = CountryData(input1, input2, input3)
Because it is a constructor method, you do not need to provide the object as an input.
Once you have created an instance of the course, you would use dot notation to access the individual properties. For example
app.Data.Country

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Construct and Work with Object Arrays finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2018a

Gefragt:

am 16 Sep. 2021

Kommentiert:

am 18 Sep. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by