How can I do the following with MATLAB Editor

2 views (last 30 days)
I purchased matlab license 2 days ago and coming from a Python background, language similarities seems to be a smooth transition. However, there are a few things that I find missing at this point in the editor, perhaps someone could advise me on the following points:
  1. How to enable indenting in command window as well just like how we can enable it for the editor.
  2. How does 'path' work? It seems to be defaulted at Documents/MATLAB/. How do you organize and manage your project files from this point on?
  3. How do you configure your matlab code in such a way that for example, I want to reformat my code with whitespace around any operator or a whitespace before any keyword. For example the two lines of code below have an imbalanced whitespace distribution. This irks me. I want a neat code. Is there a way to do this w/o depending on external (3rd party) scripts or functions
%impropper whitespace balance befor/after operator
fidRead= fopen(fileName,'r');
fidWrite =fopen(bufferFile,'w');
%space before keyword
tline = fgetl(fidRead);
%no space before keyword
tline =fgetl(fidRead);
At this point I believe MathWorks is undergoing some technical issue with their servers, one cannot play any video tutorials on their website.
  2 Comments
Abhilash Sukumari
Abhilash Sukumari on 15 Nov 2017
I have created something called MATLAB-Projects folder. So this is like a windows explorer? In other words if I want to work on a project "A". I would just browse to MATLAB-Projects/A ?
Then what is SET PATH under HOME ribbon? and what's that 'Add to Path' option when you right click on any folder in command window?
Which one should I follow to work in a given project folder?

Sign in to comment.

Accepted Answer

per isakson
per isakson on 15 Nov 2017
Edited: per isakson on 24 Nov 2017
  1. Unknown in the Matlab world. Who would want that ;-)
  2. Good question. See What Is the MATLAB Search Path?. Use Packages Create Namespaces even if it requires more planning and typing. It requires a lot of manual work to organize a code base with packages afterwards. I have all my matlab code in subfolders under a folder named, "m", far away from the Matlab installation. And see the blog-post Best Practices – Adapt, then Adopt!
  3. Unknown in the Matlab world. We do that by typing and ask our-self what editor The MathWorks use in-house. The wish-list regarding the editor is long. I use Notepad++ when I "must" have regular expressions and more ... .
  4. Now "video tutorials on their website" are up and running.
"In other words if I want to work on a project "A"."
  1. Create the folder: MATLAB-Projects/A
  2. Add A to the MATLAB Search Path, which can be done in at least four different ways. There is a Set Path GUI under the HOME-ribbon, a command addpath, right click context menu, and more. That is good for the current session. To add it permanently you have to Save Path.
Live Edit might be the first manifestation of Matlabs new editor. See Introduction to the Live Editor
  2 Comments
per isakson
per isakson on 16 Nov 2017
Edited: per isakson on 16 Nov 2017
  • The main effect of adding a folder to the search path is that Matlab looks in that folder for executable files. See Files and Folders that MATLAB Accesses. Thus, Matlab will find your script in MATLAB-Projects/A.
  • dir is a different story. It doesn't scan the search path. See dir, List folder contents. (Matlab has evolved over a period of forty years. Old features are not easily removed, because that would alienate the users. That explains ... .) In your script use something like sad = dir(glob), where glob is a string, which may include wildcards. IMO: don't make scripts, the behavior of which depends on the value of the current folder.
  • "The only way" No! There are two alternatives. 1) Use a sandbox, make that the current folder, keep all files in that folder. That's good for small experiments. 2) Write the script/function so that it does not depend on the current folder.
  • BTW: For serious programming use functions and classes, not scripts.

Sign in to comment.

More Answers (0)

Categories

Find more on Search Path in Help Center and File Exchange

Tags

No tags entered yet.

Products

Community Treasure Hunt

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

Start Hunting!

Translated by