本文介绍了在Matlab中发布被调用的(使用的)函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在matlab中发布被调用的函数?当我单击带有脚本文件的发布"时,我希望被调用的功能也成为发布文档的一部分.在2016b中,这似乎是内置的,但我在2015a中看不到.对于这种区别,我也找不到足够的文档.

How can I publish called functions in matlab ? When I click on Publish with the script file I would like the functions being called also to be a part of the published document. In 2016b this seems inbuilt but I dont see this in 2015a. I also do not find any sufficient documentations on this difference.

示例:

%% 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

推荐答案

我认为这在2015a中是不可能的,因为仅在2016b中才引入了将功能代码包含在脚本中(而不是在单独的文件中)的功能.

I assume this is not possible in 2015a because the ability to include function code within scripts (instead in a separated file) was introduced only in 2016b.

https://fr.mathworks.com /help/matlab/matlab_prog/local-functions-in-scripts.html

如果要在2015a中这样做,则应将函数GetDiff和GetSum放在单独的m文件中.然后,在您的主脚本中,添加以下发布标记:

If you want to do so in 2015a, you should put the functions GetDiff and GetSum in separated m-files. Then, in your main script, add the following publishing markup:

%% 
% <include>GetDiff.m</include>
% 
% <include>GetSum.m</include>

这篇关于在Matlab中发布被调用的(使用的)函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 04:30