Using a generated struct within a function
조회 수: 3 (최근 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에서 Classification Learner App에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!