I solved several small problems in sections using section divider %% Section. I ran each sections & every section worked. Today I opened the file, %% Sections are there, but section dividers are not working. How to correct the situation. Thanks Abu Sarwar

1 Kommentar

Jan
Jan am 8 Jan. 2017
What does "section dividers are not working" exactly mean?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Stephen23
Stephen23 am 8 Jan. 2017
Bearbeitet: Stephen23 am 8 Jan. 2017

1 Stimme

Cell mode can be enabled or disabled from the Cell menu.
Different versions of MATLAB might put this in different places, but on my ancient R2010b it is located on the main editor menu bar:

1 Kommentar

Jiangdong Collignon
Jiangdong Collignon am 7 Mai 2021
In MATLAB R2018b, you go to tab HOME -> Preferences -> Editor/Debugger -> Autoformatting and then you tick the boxes in section break.
Personally, I had it on and the it still didn't work but I found out why : I put my function at the beginning of my script by accident so from that section, I couldn't split the script into sections with %%. Just put your function at the end of your script and it maybe it'll work for you too :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (5)

DGM
DGM am 5 Mai 2023
Bearbeitet: DGM am 5 Mai 2023

1 Stimme

It's also worth noting that having open scopes, imbalanced parentheses/brackets, or other gross errors can break the handling of section breaks. It's a bit moot, since invalid code won't run anyway, but that might be one reason your section highlighting suddenly stops working.
A = [1 2 3; % this is an error
%% oh no my cell divider doesn't work!
B = 12.34; % some other code
the cyclist
the cyclist am 8 Jan. 2017

0 Stimmen

Are you referring to cell mode? If so, can you post the code that is not working as you expect?
Did you try simple things like saving and re-opening the file, or restarting MATLAB?

1 Kommentar

Abu Sarwar
Abu Sarwar am 8 Jan. 2017
I am a new user. Yesterday I tried to go cell mode, but I think I was not successful. I do not know how to go "cell mode". The problem happened after my attempts to go to cell mode. Following is an example of two sections:
%% if == test using simple example
a=input('Enter a = ')
b= input('Enter b = ')
if a==b c=2*a^2
elseif a>b deltaab=a-b
else deltaba=b-a
end
%% use of && ==
m=input('Enter m = ')
n= input('Enter n = ')
if m>4 && n>10 mg4ng10=m*n
elseif m==4 n==10 mnn=m*n^2
else mmn=m^2*n
end

Melden Sie sich an, um zu kommentieren.

Image Analyst
Image Analyst am 8 Jan. 2017
Bearbeitet: Image Analyst am 5 Mai 2023

0 Stimmen

And how did you try to execute it? Did you use the green Run triangle or F5, OR did you try Step or F10? Which way? Using F5 will just blast through everything without stopping at cells whereas F10 will stop at cells.
Also make sure the Section Break checkboxes are checked in the Autoformatting preferences:

2 Kommentare

Abu Sarwar
Abu Sarwar am 8 Jan. 2017
I went to Editor & tried different ways, but not sure what I tried. I always run a section by placing mouse on a desired section & select "Evaluate Current Section". Thanks
Abu Sarwar
Abu Sarwar am 8 Jan. 2017
It is working. Thanks all

Melden Sie sich an, um zu kommentieren.

Megan Yip
Megan Yip am 20 Jan. 2021
Verschoben: Image Analyst am 5 Mai 2023

0 Stimmen

For anyone eldr who had this problem, make sure that if you have text after the %%, that you have a space between the second % and the first text character. For example, use
%% Section Name
which will work, rather than
%%Section Name
which won't work.
GANDI RAVIKUMAR
GANDI RAVIKUMAR am 4 Mai 2023

0 Stimmen

May be below is the one of the reason..
Check your file name with which you have saved.
File name should not have any spaces, if it contains any spaces just rename it and remove spaces then it might work.
Check once.
Thank you...!!!!1

Produkte

Gefragt:

am 8 Jan. 2017

Bearbeitet:

DGM
am 5 Mai 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by