Using a generated struct within a function
2 ビュー (過去 30 日間)
古いコメントを表示
Hi all, I have generated some functions using the classification learner app and exported them to the work space. They appear within the workspace as a 1x1 struct. I have attempted to create a funtion that will read newly generated data and input into these classification functions to output what class the data is approximatley in. The issue is when I attempt to use the Train function there is an error as the x.predictFcn( C ) is not found. Is there a way I can put the predict function within my function? Thank you
function [C2,C10,C100] = Train(Pump,Date)
c = sprintf('%s_Current.%s.csv',Pump,Date)
if exist(c)
C = xlsread(c);
C = C([1:end],[2:end]);
C2 = mean(C2A635.predictFcn(C));
C10 = mean(C10A461.predictFcn(C));
C100 = mean(C100A208.predictFcn(C));
else
C2 = 'NaN';
C10 = 'NaN';
C100 = 'NaN';
end
end
0 件のコメント
回答 (1 件)
Simon Mählkvist
2019 年 6 月 4 日
You can't access your local workspace from the function. Try adding x.predictFcn() to the function input as such:
function [C2,C10,C100] = Train(Pump,Date,x.predictFcn)
3 件のコメント
Simon Mählkvist
2019 年 6 月 4 日
I was trying to be generall. The function Train need all data it is going to use and as such the functions you have created needs to be insterted or saved as proper functions.
Try this instead:
function [C2,C10,C100] = Train(Pump,Date,C2A635.predictFcn,C10A461.predictFcn,C100A208.predictFcn)
c = sprintf('%s_Current.%s.csv',Pump,Date)
if exist(c)
C = xlsread(c);
C = C([1:end],[2:end]);
C2 = mean(C2A635.predictFcn(C));
C10 = mean(C10A461.predictFcn(C));
C100 = mean(C100A208.predictFcn(C));
else
C2 = 'NaN';
C10 = 'NaN';
C100 = 'NaN';
end
end
参考
カテゴリ
Help Center および File Exchange で Get Started with Statistics and Machine Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!