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

192 Ansichten (letzte 30 Tage)
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 Kommentar
Jesus Manotas
Jesus Manotas am 6 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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.

Weitere Antworten (2)

Cris LaPierre
Cris LaPierre am 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 Kommentare
Cris LaPierre
Cris LaPierre am 5 Feb. 2021
You should be able to use either single or double quotes.
I did think of a third way to do it. You can programmatically change your current folder just before loading the file, then change it back. That might look like this (borrowed from one of my scripts).
% Capture current folder
here=cd;
% Change current folder for loading
cd('/MATLAB Drive/MobileSensorData/');
load drop4.mat
% Change back to the original folder
cd(here);
The only thing to be aware of here is that, if there is an error during loading, your current folder will not have changed back.
Cris LaPierre
Cris LaPierre am 5 Feb. 2021
Bearbeitet: Cris LaPierre am 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')

Melden Sie sich an, um zu kommentieren.


Gareth
Gareth am 11 Mär. 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 Kommentare
Walter Roberson
Walter Roberson am 12 Mär. 2021
Ah, MATLAB Online is only at R2020b at the moment, so this does not work for MATLAB Online yet.
And it turns out that the Run feature of Answers is not connected to our personal MATLAB Drive, so we would have to use a shared link to use from the Run feature. But that has problems too...
imshow('https://drive.matlab.com/sharing/901abb7d-27ae-4e2b-9e76-be269b351d3e/q770137.jpg');
Error using images.internal.getImageFromFile (line 13)
Cannot find the specified file: "https://drive.matlab.com/sharing/901abb7d-27ae-4e2b-9e76-be269b351d3e/q770137.jpg".

Error in images.internal.imageDisplayParseInputs (line 75)
images.internal.getImageFromFile(common_args.Filename);

Error in imshow (line 253)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Gareth
Gareth am 26 Mär. 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by