Skip to content

Latest commit

 

History

History
80 lines (51 loc) · 2.55 KB

loading-from-the-web.md

File metadata and controls

80 lines (51 loc) · 2.55 KB

Loading stuff from a website directly

Rather than saving a file by hand (copy/paste or right-clicking and using "Download as..."), you can also get data straight in the Terminal and also in matlab

UNIX

In the terminal, try the following:

curl https://raw.githubusercontent.com/schluppeck/dafni/master/matlab_text/mystery-timecourse.txt

This will download the contents of the file at that location and put them in the terminal (technically, stdout).

You can redirect this into a file using the > operator, thus:

curl https://raw.githubusercontent.com/schluppeck/dafni/master/matlab_text/mystery-timecourse.txt > mystery-timecourse.txt

# should run silently - unless there is an error
# and then it should be present!
ls my*

# the same works for other formats, too
curl https://farm8.staticflickr.com/7342/26661994064_4966d46cb3_c.jpg > mystery-image.jpg

# inspect
open mystery-image.jpg

During the download process you may see a message about progress. For very big files, this is very useful:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed
100 52739  100 52739    0     0   143k      0 --:--:-- --:--:-- --:--:--  143k

Matlab

Matlab also has some tools to do this. You can look at the help for webread() and websave()

% make sure matlab uses the right tool to read NUMBERS
options = weboptions('ContentReader', @importdata)
% download into a variable:
m = webread('https://raw.githubusercontent.com/schluppeck/dafni/master/matlab_text/mystery-timecourse.txt', options);
% and plot in a figure
figure, plot(m, 'r-')

You can also try an image:

anImage = webread('https://farm8.staticflickr.com/7342/26661994064_4966d46cb3_c.jpg', options);
% and show
figure, imshow(anImage), title('A lambertian brain')

Back to main

Go back to today's session aims

Notes