Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB Code Sections - Script vs. Function

When using Code Sections / Code Cells / Cell Mode (%%) in MATLAB R2014a and R2014b (see these two MathWorks links), the section highlighting within the editor works fine with both scripts and functions.
However, the sections are shown correctly in the Details Panel of the Current Folder window only for scripts and not for functions, see the lower left corner in the following two screenshots:

Section View in Current Folder is working for a Script

Section View in Current Folder is not working for a Function

Is there a setting to change this behaviour? I do very much appreciate the section view in the Details Panel of the Current Folder window, as it shows the overall structure of the script and allows easy navigation, which I would like to get for functions as well.

like image 982
Discbrake Avatar asked Jul 11 '17 10:07

Discbrake


People also ask

How do I run a section in MATLAB?

With the cursor in the code section, on the Editor tab, in the Run section, click Run Section. In MATLAB Online, the Run Section button is located in the Section section. Run the code in the current section, and then move to the next section. With the cursor in the code section, on the Editor tab, in the Run section, click Run and Advance.

What is the difference between a Matlab script and function?

Whenever you are going to perform a specific functionality by using MATLAB code you either go for a MATLAB script or a MATLAB function. MATLAB script is the simplest form of the MATLAB file in which you can write your MATLAB code in any way allowed by the MATLAB rules.

What is a Code section in MATLAB?

A code section contains contiguous lines of code that you want to evaluate as a group in a MATLAB script, beginning with two comment characters (%%). To define code section boundaries explicitly, insert section breaks using these methods: On the Editor tab, click (or Section Break in MATLAB Online™).

How do I run a script in MATLAB?

With the cursor in the code section, on the Editor tab, in the Run section, click Run and Advance. In MATLAB Online, the Run and Advance button is located in the Section section. Run all the code in the file. On the Editor tab, in the Run section, click Run. You also can type the saved script name in the Command Window.


1 Answers

There currently doesn't appear to be any way to customize the Details Panel of the Current Folder browser. It shows you the underlying structure of a file in a way that is specific to the type of file. For scripts it shows the section structure, since sections are the only real way to partition a script.

For functions, partitioning of the code is generally accomplished by grouping operations into subfunctions, so the local function structure in the file is shown (but nested functions, for whatever reason, are not). Additionally, class files will display object properties and methods, while MAT-files will display their variable contents.

like image 76
gnovice Avatar answered Sep 28 '22 01:09

gnovice