0
votes

I would like to be able to download and open csv files from a known address through the Octave interface, without having to download the files and move them to the current folder separately. I am looking at downloading a large number of csv files and it will be a pain to do by hand.

Ideally I would type something like dlmread('http://...csv') and have Octave find the file for me. Of course, this doesn't work.

A solution for Matlab would also work for me. Thanks.

1
See urlread to download in Octave. gnu.org/software/octave/doc/v4.0.0/URL-Manipulation.htmlAndy

1 Answers

0
votes

It sounds like what you're asking isn't specifically an octave / matlab native way of downlading the files, but simply a way to automate the downloading and reading of the csv files within a script, to avoid the need to download and move files manually before running your octave script, is that correct?

The urlread suggested in the comment above is one way, but then you'd be stuck with a string that you'd have to interpret as data yourself.

My approach would be to just use the system function to run a downloader command from the underlying OS. I would recommend wget. It comes ready in linux, and you can download a windows wget.exe version as well. This means wget would take care of the downloading for you, and then you'd open your .csv file using standard csv facilities like csvread.

So to download and process a batch of csv files, your script might look something like this:

for n = 1 : 10
  wgetCommand = sprintf ('wget http://path/to/my/data%d.csv', n);
  Exitcode = system (wgetCommand);
  assert (Exitcode == 0, sprintf ('%s failed!\n', wgetCommand));
  M = csvread (sprintf('./data%d.csv', n));
  % ... do something with M
end