MATLAB Community

MATLAB,社区等

稍作帮助

Let’s say you’ve written some code that you think might worth adding to the File Exchange. But then you hesitate. Your Tiddlywinks Trajectory Simulator function (TiddleSim.m) is nifty. It’ll definitely be the first of its kind on the site. But you ask yourself: Should I really put this on the File Exchange? Or will everybody think I’m lame and criticize me for being a bad coder?

My friend, I’m here to encourage you to submit that file.

并非每个人都会发现它很有趣,但我保证您会有人。而且我知道大幅度增加发现它有趣的人数的秘诀。这里是。

The very best way to get people to use and enjoy your code is to include some help and examples in your function comments.

Is there a standard way to do that? Yes there is. Take a look atthis documentation page. It spells out how we structure function help here at MathWorks. You don’t have to use this format, but it’s served us very well, and if you do you’ll be using a standard that people around the world are familiar with. So I’m going to strongly recommend that you use it unless you have compelling reasons not to.

The anatomy of function help, at its simplest, is this. Just below the function signature you put the H1 line. This is followed by the calling syntax. At the end you might want to link to other functions in a See Also line.

这是一个复杂的函数称为ADDME。我们ll use it as our help model.

addme

H1线非常巧妙。这是您在功能上键入帮助时看到的第一行(即“帮助添加”)。H1线从函数的名称开始,然后是一个简短的句子(必须适合一行!),描述了该功能。

如果您已经做到了这么远,并且您真的想通过您的功能来震撼世界,请在帮助下添加一些示例。这样,人们不仅可以看到抽象的调用语法,而且可以看到它的外观。

I dipped into the File Exchange and found a popular function with terrific help:Fast ‘n easy smoothing写的Damien Garcia. Download it and look at the help. It starts off like this.

>>帮助平滑smoothnRobust spline smoothing for 1-D to N-D data.smoothn为任意维度的数据提供快速,自动化和可靠的离散的样条平滑。

But it goes on and on from there, with lots of detail and references, and no fewer than eight (!) examples. Beautiful! That, my friends, is how you make your code helpful.

Since Damien works in a进行心脏成像的实验室, it’s only appropriate that I should include this example from his file: smoothing a cardioid.

t = linspace(0,2*pi,1000); x = 2*cos(t).*(1-cos(t)) + randn(size(t))*0.1; y = 2*sin(t).*(1-cos(t)) + randn(size(t))*0.1; z = smoothn({x,y}); plot(x,y,'r.',z{1},z{2},'k','linewidth',2) axis equal tight

cardioid

Be like Damien. Have a heart. Think of your File Exchange friends. A little help can make all the difference.

|
  • print
  • send email

注释

To leave a comment, please click这里to sign in to your MathWorks Account or create a new one.