Using a generated struct within a function

1 次查看(过去 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

回答(1 个)

Simon Mählkvist
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
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
Stephen23
Stephen23 2019-6-4
编辑:Stephen23 2019-6-4
function [C2,C10,C100] = Train(Pump,Date,C2A635.predictFcn,C10A461.predictFcn,C100A208.predictFcn)
% Not valid for a function definition: ^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by