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
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!