如何在matlab中发布调用的函数?当我单击脚本文件的Publish时,我希望被调用的函数也是已发布文档的一部分。在2016b,这似乎是内置的,但我不会在2015a看到这一点。我也没有找到关于这种差异的任何足够的文档。
示例:
%% HW-5 Q.1.a
% clear command screen and close all open figures if present
clc;
close all;
% display title: HW-#-Question.Number.SubSection
disp('HW-5-Q.1.a');
disp('Start of Program!');
A = 5;
B = 2;
res = 'The result is: ';
GetSum(A, B, res);
GetDiff(A,B, res);
disp('End of Program!');
function [ ] = GetDiff( num1, num2, StringRes )
%GETDIFF Summary of this function goes here
% Detailed explanation goes here
R = num1 - num2;
X = ['For Sum: ', StringRes, num2str(R)];
disp(X);
end
function [ ] = GetSum( num1, num2, StringRes )
%GETSUM Summary of this function goes here
% Detailed explanation goes here
R = num1 + num2;
X = ['For Sum: ', StringRes, num2str(R)];
disp(X);
end发布于 2017-02-22 22:02:04
我假设这在2015a是不可能的,因为在脚本中包含函数代码(而不是在单独的文件中)的能力是在2016b中才引入的。
https://fr.mathworks.com/help/matlab/matlab_prog/local-functions-in-scripts.html
如果你想在2015a这样做,你应该把函数GetDiff和GetSum放在分开的m文件中。然后,在您的主脚本中,添加以下发布标记:
%%
% <include>GetDiff.m</include>
%
% <include>GetSum.m</include>https://stackoverflow.com/questions/40807745
复制相似问题