Not enough Input Argument error

4 ビュー (過去 30 日間)
PADMAKAR
PADMAKAR 2021 年 9 月 16 日
コメント済み: Cris LaPierre 2021 年 9 月 18 日
% 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 件のコメント
PADMAKAR
PADMAKAR 2021 年 9 月 18 日
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 2021 年 9 月 18 日
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.

サインインしてコメントする。

回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 9 月 16 日
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 件のコメント
PADMAKAR
PADMAKAR 2021 年 9 月 18 日
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
Cris LaPierre
Cris LaPierre 2021 年 9 月 18 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeConstruct and Work with Object Arrays についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by