MATLAB Answers

0

How do I set up a project or solution?

Asked by Mark Hayworth on 13 Jun 2014
Latest activity Answered by Image Analyst
on 19 Apr 2019
My guess is that we can't , but I'll ask anyway...
I would like to be able to have project files, where I have a collection of files that are relevant/needed for a particular project. Opening the project file would open all those files, and optionally close any other files that are already open in the editor. For example I specify that files f1.m, f2.m, and f3.m belong to project1.prj. Then when I open project1.prj, it will open those 3 files and (optionally) close any other files that I had open in the text editor. Many other programmer editors (e.g. Microsoft Visual Studio) can do this. How do I do it in MATLAB?
I supposed I could create a shortcut where it uses some of Yair's undocumented functions to close editor windows and then use the edit() function to open the m-files that I want, but surely there must be a better way already (after 20+ years of MATLAB). Or there should be a better way if there's not one yet. Maybe I should add it to this thread and notify tech support.

  0 Comments

Sign in to comment.

2 Answers

Answer by Kelly Kearney
on 13 Jun 2014

I don't know of any way to do that in the Matlab editor. If you're on a Mac, you could try TextMate with the matlab bundle. Textmate supports projects; it's my goto editor for all non-Matlab code, and I occasionally switch over to using it instead of the Matlab editor when I need to work in project-mode. But it's not an ideal solution, since you lose a lot of features of the Matlab editor (debugging being the most important one for me).

  0 Comments

Sign in to comment.


Answer by Image Analyst
on 19 Apr 2019

MATLAB now (in R2019a) has “projects” where you can keep collections of files. See Working with Projects
For example say I had
  • 10 files that I typically have open when working on one project, and
  • 7 other files that I typically had open when working on project #2, and
  • 5 other files open when I work on project #3.
You can build, through code, a project where you load all the files.
But the big disadvantage is that all the files you want to have in a certain project MUST live in a subfolder of the folder where the project file lives. I don’t have this. I have files in folders for that particular project, and then other files in other folders, like “test” or “utilities” folders that also have files I'd like to load. If you try to add files not under the project file folder, you’ll get an error (and I did). Since some of my files are in folders, like "Utilities" that multiple projects use, I don't want to make copies of that under each project folder. So I won't be using the new projects capability yet (unless I did not understand how to add files and you really can do that).
So, as a workaround, I’m thinking of making my own shortcut/quick access button that closes all editor windows and opens only the ones I want. I got this code from Yair Altman of UndocumentedMATLAB.com that will close all editor windows:
jEditor = com.mathworks.mlservices.MLEditorServices.getEditorApplication;
jDocs = cell(jEditor.getOpenEditors.toArray); % cell-array of com.mathworks.mde.editor.MatlabEditor objects
for k = 1 : length(jDocs)
fprintf('Closing %s\n', jDocs{k}.getLongName);
jDocs{k}.close
end
After that, you could load the specific files you want, for example
edit file1.m
edit file2.m
etc. You could type that code into a Quick Access toolbar button on the upper right so that you can just click that and open only the files you want.

  0 Comments

Sign in to comment.