Hi, I am new to Matlab. When typing in a line of code, nested in it is a helper function, can someone assist me with the correct placement of the helper function.unction
조회 수: 2 (최근 30일)
이전 댓글 표시
This is the line of code:
allTrainLabels = pixelLabelDatastore(trainLabelsPath, classNames, pixelLabelIDs, ReadFcn=@readLabelData);
This is the helper function for ReadFcn=@readLabelData:
function labelData = readLabelData(filename)
rawData = imread(filename);
rawData = imresize(rawData, [350 350]);
labelData = uint8(rawData);
end
Can you show me where do i place the helper function so that the code can be executed without an error.
Thank you
댓글 수: 0
채택된 답변
Sam Chak
2024년 2월 1일
Hi @Augustine
In the past, the convention was to save the helper function as a standalone m-file, typically placed in the same folder as the Main Program (script) file. However, starting from R2016b, it is possible to place the helper function inside a script. In this case, the helper function should be positioned at the end of the file, after the script code.
%% Main Program (script)
...
...
...
% end of script
%% Local function
function y = helper(x)
...
end
If the Main Program is implemented as another function file, then the helper function can be placed using the nested approach.
function main
...
...
...
function y = helper(x)
...
end
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!