Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Handling large code files

Subject: Handling large code files

From: james bejon

Date: 9 May, 2012 08:52:09

Message: 1 of 12

Dear All,

Matlab's editor obviously has various interactive features. (It colours what you've written, provides auto-complete stuff, etc.). I'm currently working on a script that's 5,000 lines long and counting. (I know, I know, ...). This means for everything I type, there's a lag while Matlab handles what I've written. Question is, Is there any way of turning this aspect of Matlab's editor off and on? (I suppose I can always code in Notepad++ or something and then paste it into Matlab afterwards but was wondering if there was a better--other than keeping my files smaller).

Cheers,

James

Subject: Handling large code files

From: Bruno Luong

Date: 9 May, 2012 12:22:06

Message: 2 of 12

"james bejon" wrote in message <jodb7p$hjl$1@newscl01ah.mathworks.com>...
> Dear All,
>
> Matlab's editor obviously has various interactive features. (It colours what you've written, provides auto-complete stuff, etc.). I'm currently working on a script that's 5,000 lines long and counting. (I know, I know, ...). This means for everything I type, there's a lag while Matlab handles what I've written. Question is, Is there any way of turning this aspect of Matlab's editor off and on? (I suppose I can always code in Notepad++ or something and then paste it into Matlab afterwards but was wondering if there was a better--other than keeping my files smaller).

I have no problem of editing 5000 lines file.

Bruno

Subject: Handling large code files

From: Steven_Lord

Date: 9 May, 2012 13:49:21

Message: 3 of 12



"james bejon" <jamesbejon@yahoo.co.uk> wrote in message
news:jodb7p$hjl$1@newscl01ah.mathworks.com...
> Dear All,
>
> Matlab's editor obviously has various interactive features. (It colours
> what you've written, provides auto-complete stuff, etc.). I'm currently
> working on a script that's 5,000 lines long and counting. (I know, I
> know, ...). This means for everything I type, there's a lag while Matlab
> handles what I've written. Question is, Is there any way of turning this
> aspect of Matlab's editor off and on? (I suppose I can always code in
> Notepad++ or something and then paste it into Matlab afterwards but was
> wondering if there was a better--other than keeping my files smaller).

While you can disable some of the "interactive features" using the
Editor/Debugger and Code Analyzer preferences (accessible via the File ->
Preferences menu) I would recommend splitting that script into smaller
chunks. Sometimes keeping straight what variables mean what can be difficult
in a 500-line function; it would probably be more than ten times worse in a
file that's ten times as long.

Keep in mind that you can call one script file from another and they'll
operate in the same workspace.

% begin mainscript.m
step1;
step2;
step3;
step4;
% end mainscript.m

% begin step1.m
x = 1:10;
y = x.^2;
% etc
% end step1.m

Assuming none of the %etc stuff in step1 cleared x or y, the step2 script
would have access to them.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Handling large code files

From: james bejon

Date: 9 May, 2012 19:07:05

Message: 4 of 12

Thanks for the responses. Pretty much all the variables I'm using are loaded in from "outside" in a couple of large structs. So, there wasn't really a need to split the code up into a number of different scripts. Still, wish I had done so now! I wonder why Bruno's not having problems with such files though. Either way, I'll try the Preferences and see if it helps.

James.

Subject: Handling large code files

From: james bejon

Date: 10 May, 2012 21:58:13

Message: 5 of 12

Steve,

Which fields in the Preferences menu did you have in mind? Nothing I change really makes much of a difference. I take your point that 5,000 lines of code is a lot to have in one file. That said, the editor has practically ground to a halt now; which I regard this as a fairly fundamental flaw. I've never come across any other IDEs which struggle in this way.

Subject: Handling large code files

From: matt dash

Date: 10 May, 2012 23:02:43

Message: 6 of 12

"james bejon" wrote in message <johdlk$3in$1@newscl01ah.mathworks.com>...
> Steve,
>
> Which fields in the Preferences menu did you have in mind? Nothing I change really makes much of a difference. I take your point that 5,000 lines of code is a lot to have in one file. That said, the editor has practically ground to a halt now; which I regard this as a fairly fundamental flaw. I've never come across any other IDEs which struggle in this way.

I dont have a problem with that many lines either, but sometimes when I have matlab open too long the editor gets sluggish for no apparent reason. Have you tried just restarting?

Subject: Handling large code files

From: Nasser M. Abbasi

Date: 10 May, 2012 23:12:27

Message: 7 of 12

On 5/10/2012 6:02 PM, matt dash wrote:

> I dont have a problem with that many lines either, but sometimes when
>I have matlab open too long the editor gets sluggish for no apparent reason.
> Have you tried just restarting?

I noticed that when using GUIDE and have it open for long
time also. When Matlab starts to slow down, I immediately
save everything and restart, and all is well.

I think it is Java's fault. It uses too much memory and
does not release it or something like this. (poor
Java, everyone blames it these days whenever something is
wrong).

--Nasser

Subject: Handling large code files

From: Bruno Luong

Date: 11 May, 2012 05:26:34

Message: 8 of 12

"Nasser M. Abbasi" <nma@12000.org> wrote in message
>
> I noticed that when using GUIDE and have it open for long
> time also. When Matlab starts to slow down, I immediately
> save everything and restart, and all is well.
>
> I think it is Java's fault. It uses too much memory and
> does not release it or something like this. (poor
> Java, everyone blames it these days whenever something is
> wrong).
>

What is there a connection between GUIDE and the editor?

Bruno

Subject: Handling large code files

From: Nasser M. Abbasi

Date: 11 May, 2012 05:29:18

Message: 9 of 12

On 5/11/2012 12:26 AM, Bruno Luong wrote:
> "Nasser M. Abbasi"<nma@12000.org> wrote in message
>>
>> I noticed that when using GUIDE and have it open for long
>> time also. When Matlab starts to slow down, I immediately
>> save everything and restart, and all is well.
>>
>> I think it is Java's fault. It uses too much memory and
>> does not release it or something like this. (poor
>> Java, everyone blames it these days whenever something is
>> wrong).
>>
>
> What is there a connection between GUIDE and the editor?
>
> Bruno

Matlab itself?

Matlab uses Java?

--Nasser

Subject: Handling large code files

From: Bruno Luong

Date: 11 May, 2012 06:02:32

Message: 10 of 12

"Nasser M. Abbasi" <nma@12000.org> wrote in message
>
> Matlab itself?
>
> Matlab uses Java?

Too generic to me. I'm 100% not sure the editor engine has anything to do with Java, but if someone could correct me.

Bruno

Subject: Handling large code files

From: Nasser M. Abbasi

Date: 11 May, 2012 06:13:12

Message: 11 of 12

On 5/11/2012 1:02 AM, Bruno Luong wrote:
> "Nasser M. Abbasi"<nma@12000.org> wrote in message
>>
>> Matlab itself?
>>
>> Matlab uses Java?
>
> Too generic to me. I'm 100% not sure the editor engine has anything to do
> with Java, but if someone could correct me.
>
> Bruno

Well, you could be very well correct Bruno. I do not know, since I
do not have access to the internals of Matlab. Only someone who
works at Mathworks does.

It is just a hypothesis.

If I use program A, and part of program A slows down due it use
of X, and then someone else says they are using program A,
and different part of it is also slowing down, it is logical to
speculate that it could be to also the use of X by the program.

After all, it is the same program.

Any way, just restarting Matlab when it slows down, and all
will be well.

btw,I've had slow down using Mathematica editor, known
problem, when the code size goes over few thousands lines
in one cell. The trick there was to turn off syntax coloring.
Then the editor became very fast again.

--Nasser

Subject: Handling large code files

From: Steven_Lord

Date: 11 May, 2012 14:21:35

Message: 12 of 12



"james bejon" <jamesbejon@yahoo.co.uk> wrote in message
news:johdlk$3in$1@newscl01ah.mathworks.com...
> Steve,
>
> Which fields in the Preferences menu did you have in mind? Nothing I
> change really makes much of a difference. I take your point that 5,000
> lines of code is a lot to have in one file. That said, the editor has
> practically ground to a halt now; which I regard this as a fairly
> fundamental flaw. I've never come across any other IDEs which struggle in
> this way.

The Preferences panel has changed slightly in different releases, and I
don't know which release you're using but the specific sections I was
thinking of are (from the release R2012a documentation; Your Layout Or Names
May Vary)

disable Syntax Highlighting from the Editor/Debugger item:

http://www.mathworks.com/help/techdoc/matlab_env/bs237bq-1.html#bs237bq-9

disable Code Analyzer from the Code Analyzer item:

http://www.mathworks.com/help/techdoc/matlab_env/bs24a2i.html

Both those try to do some amount of "understanding" of your code on-the-fly,
which for a really large file could be quite resource intensive. [You didn't
indicate what version of MATLAB you're using or how much memory etc. your
system has; if you're skirting close to the minimum system requirements, or
if you're trying to use MATLAB and other resource-intensive programs
simultaneously, that could be contributing to the problem as well.]

If neither of those work, please contact Technical Support and work with
them to determine why the Editor is performing so poorly for your file.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us