Hi Davide,
You are getting this error because "publish" function is used to publish the documentaion of files so as an argument you have to provide a file name. When you use "publish('funTestB',options)" then the MATLAB's publish function is looking for a separate file named "funTestB.m" to publish, but funTestB is defined as a local function within funTestA.m. The publish function expects the function to be in its own file.
You can create a temporary file within "funTestA.m" which will be containing the defination of "funTestB" function, and then run "publish" with that file name.
function funTestA(a, b)
% Define options for publishing
options = struct('format', 'html', 'outputDir', 'html');
% Create a new file that calls funTestB with the desired arguments
tempFileName = 'tempScriptToPublish.m';
tempFileContent = sprintf('result = funTestB(%d,%d);', a, b);
% Write the content to the temporary file
fid = fopen(tempFileName, 'w');
fprintf(fid, '%s', tempFileContent);
fprintf(fid, '\nfunction result = funTestB(a, b)\n');
fprintf(fid, 'result = a + b;\n');
fprintf(fid, 'disp(a + b);\n');
fprintf(fid, 'end\n');
fprintf(fid, '\n');
fclose(fid);
% Publish the temporary file
publish(tempFileName, options);
% Clean up: Delete the temporary file after publishing
delete(tempFileName);
end
For more information you can refer to the below documentation:
Hope it helps!