Clicking on hyperlink for an "example" on MATLAB command line help changes my current directory

This is not a question per se but a comment/complaint. Changing current directory is so disruptive. All I want to do is to just read the example. Anyone feel the same ?

Answers (1)

Do you want to read the example and potentially run some or all of it? I think that's a pretty common workflow for the examples. Examples may have helper files necessary to run them. Changing directory to the example's directory makes those helper files available to MATLAB.
We could stop changing directory, but then we'd have to tell you how and where you need to find those helper files when you tried to run a selection of the example. That could be very confusing and difficult (if you select a piece of the example in the Editor, copy it, and paste it into the Command Window, how would we necessarily know that the copied code originally came from an example and from which example it came?)

4 Comments

I understand the need to change directory when I run an example which is not on the path. However, merely clicking on the link to open the example does not mean I want to run it immediately. I might want to just browse it a bit to see how it is written (a lot of the times, that's what I do). When I do want to run it, the editor should prompt me to change the directory or add its dir to the path (I thought it used to do this already, did we remove this functionality?).
Changing the current directory automatically like this just by clicking a link is very disruptive.
Thanks to this behavior, I am now afraid to look at the examples. Instead, I go to the documentation page or ask chatgpt for usage info,.
Examples generally are composed of multiple files. Browsing the files together requires changing the directory -- or else having the editor open all of the relevant files at the time of opening the example (which has its own issues.)
All I am saying is that changing the directory should be optional and obvious and user initiated.

Sign in to comment.

Categories

Products

Release

R2024b

Asked:

on 1 Feb 2025

Commented:

on 2 Feb 2025

Community Treasure Hunt

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

Start Hunting!