Slow Matlab startup if startup.m contains many path additions

조회 수: 4 (최근 30일)
K E
K E 2012년 7월 3일
I am asking/answering my own question, hoping it will help someone with the same issue:
If Matlab takes 3+ minutes to start up, how can I speed it up? My startup.m file contains many calls to add directories to my path, and those directories reside on a network drive. For example:
path(path, 'S:\top_code_directory\some_subdirectory') ; % Many calls like this
path(path, genpath('S:\project_directories')) ; % Many subdirectories are added
  댓글 수: 1
Jan
Jan 2012년 7월 3일
편집: Jan 2012년 7월 4일
Please add an example for "add directories to my path". This will increase the chance, that others with the same problem will find this thread. Is the time wasted in addpath or in genpath? Thanks.

댓글을 달려면 로그인하십시오.

채택된 답변

Richard Crozier
Richard Crozier 2012년 10월 4일
편집: Richard Crozier 2012년 10월 4일
build the path yourself and do a single call to addpath, addpath expects a single string containing path names separated by semicolons. So try something like the following:
apath = 'S:\top_code_directory\some_subdirectory;'
newpath = [genpath('S:\project_directories'), apath];
addpath(newpath);
Obviously your construction of the path string to add will be more complex. Just remember that genpath already produces a string ending in a semicolon so you don't need to add one to the string produced by it.
You will find this much faster, as the bottleneck is the function path.m
  댓글 수: 1
K E
K E 2012년 10월 8일
What is nice about this solution is that I can put this in my startup file. I've had the saved path (via my original savepath approach) get corrupted a couple times so having it in my startup will be more robust. Thanks for answering after all this time - shows the value of Answers in retaining / gaining knowledge.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

K E
K E 2012년 7월 3일
편집: K E 2012년 7월 3일
Most of the 3 minutes were spent generating Matlab's path, but it is not necessary to generate the path at each startup. Instead, remove the path calls from startup.m, save it, and restart Matlab, noting a faster startup. Generate the desired path from the command prompt using the same calls that used to be in the startup.m file, then execute the savepath command. Every subsequent time Matlab starts, it loads the saved path. The improvement in startup time can be verified using the -timing option as described here. Thanks to Tech Support for showing me this solution.
  댓글 수: 3
Robert Cumming
Robert Cumming 2012년 10월 4일
By doing it this way every user of your machine will also have all your paths added. Be careful as you may not want this...
Richard Crozier
Richard Crozier 2012년 10월 4일
No, only users who have access to my startup directory which is only accessible to me, so they have to also be logged in as me. Valid point for others though. I've discovered the real answer to the problem anyway which I have posted below.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by