2015-12-03 126 views
0

所以我想写的形式传递字符串(Matlab的)

function [ output_args ] = job(n,sigma,tau,rho,p,N,'Gaussian') 

的AA功能,因为里面的功能我想通过“高斯”作为参数传递给MATLAB内建函数像

pd = makedist('Gaussian') 

所以,然后我想使用函数的多用途改变'高斯'到'吨'和其他字符串。我怎样才能实现这个?

有人能帮助我吗?提前致谢!

+5

您只需在函数的参数列表中声明变量并将该变量传递给函数体中的'makedist'。这里没有黑魔法。 – TroyHaskin

+0

如果我想通过一个数字的标题呢? – Kots

回答

0

正如TroyHaskin解释,你可以定义一个字符串参数为你的函数,并用它在你的函数体中调用MATLAB的内置函数:

function [output_args] = plot_figure(X, dist_type, my_title) 
    pd = makedist(dist_type); 
    Y = pd.pdf(X); 
    figure; plot(X,Y); 
    title(my_title); 
end 

然后,你可以尝试型动物值:

plot_figure(-10:10, 'Normal', 'Distribution plot'); 
plot_figure(-10:10, 'Gamma', 'Another distribution plot');