How to load a .mat file from a URL

16 views (last 30 days)
Matt J
Matt J on 15 Nov 2020
Commented: the cyclist on 25 May 2021
I find that I cannot load a .mat file from a URL. For example, when I try to call load() with the full URL of the attached .mat file as input, I obtain,
load('https://www.mathworks.com/matlabcentral/answers/uploaded_files/414803/tst.mat')
Error using load
Unable to read file 'https:/www.mathworks.com/matlabcentral/answers/uploaded_files/414803/tst.mat'. No such file or directory.
I have no such difficulty using imread() to read in image files from Answers URLs. Why does load() behave differently, and is there a workaround?

Accepted Answer

Ameer Hamza
Ameer Hamza on 15 Nov 2020
Edited: Ameer Hamza on 15 Nov 2020
imread() documentation mentions support for URL, but load documentation does not say anything about it. I think the closest possible thing is something like this.
load(websave('myFile', 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/414803/tst.mat'))
  4 Comments
the cyclist
the cyclist on 25 May 2021
Agreed that this is amazing functionality.
% load('tst.mat') % Commented so that this example doesn't run.
works for OP if they are the one who uploaded the file in their question. For example, I uploaded the file x.mat along with this comment, and I have access to it directly:
load('x.mat')
disp(x)
0.8147 0.1270 0.9058 0.9134
the cyclist
the cyclist on 25 May 2021
Note that I cannot access x.mat in this followup comment:
load('x.mat')
Error using load
Unable to read file 'x.mat'. No such file or directory.
disp(x)
but I could use your websave trick.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB 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!