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

251 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?
  1 Comment
Jesus Manotas
Jesus Manotas on 6 Mar 2023
Install MATLAB Drive Connector
MATLAB® Drive™ Connector provides an easy way to manage your MATLAB Drive files on your local computer. With the Connector, files synchronize automatically between MATLAB Drive online and your local MATLAB Drive when you have the Connector running.Install Instructions
To install MATLAB Drive Connector, follow these steps:
  1. Start the installer using one of these methods:
  • From within MATLAB — Click the MATLAB Drive button to start the installer.If you do not see the MATLAB Drive button in the Current Folder toolbar, right-click the toolbar and select Customize. Then, in the MATLAB Toolbar Preferences Controls section, select the check box for the MATLAB Drive control and select OK. MATLAB adds the button to the toolbar.
  • From the web — Go to the Connector download page and select Install for Windows, Install for Mac, or Install for Linux. Installing from the web does not require you to have MATLAB installed.
  1. Configure the location of your MATLAB Drive folder and your MATLAB Drive settings.NoteSetting the location of your MATLAB Drive folder to a location on a network drive is not supported. This is because MATLAB Drive is unable to sync files and folders in a network location.
  2. Click Finish to complete setup and synchronize your MATLAB Drive files between your computers and online accounts. To change any of your selections, click Back.
When the installer finishes, MATLAB Drive is ready for use on this computer. See Access Files in Your MATLAB Drive for instructions on accessing MATLAB Drive.

Sign in to comment.

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)

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.
imread('../Images/BinaryImages/binary1.bmp')
  3 Comments
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.


Gareth
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!
  3 Comments
Gareth
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,
Gareth

Sign in to comment.

Categories

Find more on Startup and Shutdown 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!