TafT
TafT

Reputation: 3095

Are Example script files in Matlab different to standard Scripts in Matlab?

In Matlab you are given the option to create new "Example" script files alongside Script, Function, Class,etc. When they are created they are given a script icon.

Are they treated any differently to other standard script files?

Is there any documentation on the intended use of these Example script types?

Matlab New > Example file in contect menu

I realise this sounds like a trivial question but I have spent quite a while on the Mathworks site trying to find any reference to it. It not often but sometimes there is a nugget of special behaviour that is not obvious without reading the background information.

Also it just really bugs me when there must be answers and I must be looking up the wrong keywords in a search.

I assume they are as different to standard scripts as the Function and Class options are but that may be a mistake.

Upvotes: 2

Views: 132

Answers (1)

TafT
TafT

Reputation: 3095

There is no significant difference between and Example script or a Standard script as created through the shown Matlab menu.

Both are Script files as far as Matlab is concerned and they will be treated equally. This is the reason no separate documentation exists for "Example" scripts.

The intended purpose of an Example script is to give a working example with a bit of background information for a Script, Function or Class file. Their existence on the New menu is to prompt the user to do so.


New Scripts are generated a blank .m file.

New Examples are generated with a small amount of comment text in them:

%% Example Title
% Summary of example objective

%% Section 1 Title
% Description of first code block
a = 1;

%% Section 2 Title
% Description of second code block
b = 2;

Again this is to prompt the user to document the example code more thoroughly. The behaviour of the code would be the same if placed in any other .m file.

There is no magic link between Examples files and any other file types they call. They are just another script file calling into some other code.

Upvotes: 4

Related Questions