How to specify a path to a file in MATLAB Drive when using MATLAB Online

248 views (last 30 days)
Using MATLAB Online I have 3 apps and some image files in MATLAB Drive. Two of the apps require the image files. The files are in the folder Images, which has several sub-folders, like 'BinaryImages'. When MATLAB Drive is my current folder, I'm unable to access any of my images with, for example, imread('Images\BinaryImages\binary1.bmp' ). I'm simply told it's a non-existent file. I've tried using the full path on my desktop: C:\Users\Stuart Smith\MATLAB Drive\Images\BinaryImages\binary1.bmp' , but this didn't work either. So what is the correct way to access my files?

Accepted Answer

Walter Roberson
Walter Roberson on 5 Feb 2021
MATLAB Online is Linux based. The directory separator is / not \ .
If you use fullfile() you do not need to know the character.
Note: Windows is fully able to use / as the character except in the old command shell.

More Answers (2)

Gareth on 11 Mar 2021
With the release of R2021a you can now use the new matlabdrive function combined with fullfile to construct a path to files in your MATLAB Drive that will work in both MATLAB Online and on the desktop.
For example in this case, the following could work:
imread(fullfile(matlabdrive, 'Images', 'BinaryImages', 'binary1.bmp'))
I hope that helps in the future!
Gareth on 26 Mar 2021
Hi Walter,
Sorry for any confusion - MATLAB Online has now updated to R2021a :)
As you demonstrated, a MATLAB Drive sharing link cannot be used directly to load a file within MATLAB - thank you for the feedback.
Best wishes,

Sign in to comment.

Cris LaPierre
Cris LaPierre on 5 Feb 2021
Are you using MATLAB online?
My suggestion is to add the images folder and subfolders to your path. Right click on the folder and select Add to path > Selected folders and subfolders. Then you can just call the images by their names.
If you want to use the path, try using a relative path. This goes up one folder level, then follows the specified path to binary1.bmp.
Cris LaPierre
Cris LaPierre on 5 Feb 2021
Edited: Cris LaPierre on 5 Feb 2021
I must have had a typo or something wrong when I tried this last night so I didn't suggest it. However, now that I'm awake I was also able to successfully use the full MATLAB Online path.
load('/MATLAB Drive/MobileSensorData/drop4.mat')

Sign in to comment.


Find more on Search Path in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by