Clear Filters
Clear Filters

Is it possible to ADD a warning before Matlab starts?

24 views (last 30 days)
Eric
Eric ungefär 8 timmar ago
Commented: dpb ungefär 4 timmar ago
So, I have the previously-reported issue that, on startup in Windows 10, Matlab reports that any folders that are on mapped network drives (Z:, Y: etc.) are "nonexistent or not a directory". I also lose any scripts or functions from those mapped folders that were open in the editor when Matlab was last shut down, so I have to find and re-open them.
The hack to get around this is to access the network drive(s) in Microsoft Windows Explorer/File Explorer, after which Matlab can see the folders in those drives - e.g. if functions or scripts were loaded into the editor, these will appear following the above hack.
What I'd like is a warning, before Matlab goes off and fails to find those mapped network drives, reminding me to open the offending drives in Windows Explorer before continuing.
Is there any way to do this via startup.m - or would it need a Windows batch file to incorporate the warning and the pause?
  4 Comments
Eric
Eric ungefär 5 timmar ago
Thanks @dpb.
I tried the bat file suggestion in your comment. Unfortunately, trying to access the drives from the command prompt (i.e. in a batch file) before they have been "made available" in File Explorer just gives the error "The system cannot find the drive specified".
It's definitely a Windows issue rather than a Matlab one, as typing "NET USE" at the command prompt shows most of my mapped network drives are "Unavailable". It's odd because some of them map OK from the command prompt or from a batch file - others are stubbornly "Unavailable" until one has clicked on them in File Explorer. Bizarre.
It is possible to add "explorer Z:" to the batch file, and then Windoids will open up the mapped drive in a File Explorer window. Again, not super-elegant, but it works, and Matlab can then see folders on that drive.
dpb
dpb ungefär 4 timmar ago
"... the automatic reloading into the editor can't happen unless they are mapped at that time."
I haven't actually thought to test because I have the development environment on the local machine and only data files are on the shared drives, but I'd think if you simply typed edit after mapping the drives however that it would then load the previously open files again...unless it tries to be to clever and clears the past history of files that weren't available; that behavior I'm not sure about.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst ungefär 4 timmar ago
Edited: Image Analyst ungefär 4 timmar ago
You can check for drives in your startup.m file, and warn you if the folder or drive is not there, like this
missingFolder = false;
folder = 'X:\';
if ~isfolder(folder)
warningMessage = sprintf('Warning: %s folder not found!', folder);
uiwait(warndlg(warningMessage));
missingFolder = true;
end
folder = 'Z:\my MATLAB files';
if ~isfolder(folder)
warningMessage = sprintf('Warning: %s folder not found!', folder);
uiwait(warndlg(warningMessage));
missingFolder = true;
end
if missingFolder
% Open File Explorer to the current folder if we didn't find one.
winopen(pwd);
end
If you have some top level folder where all your m-files live, even in subfolders, you can use the Setpath button on the tool ribbon to "Add with subfolders" the folder, then save the path. Or you can put this into your startup.m file:
folder = 'Z:\my MATLAB files';
addpath(genpath(folder));
savepath();
  1 Comment
Eric
Eric ungefär 4 timmar ago
Nice. I'll try that tomorrow, but the suggestion looks promising.

Sign in to comment.

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!