Search code examples
matlabreadfile

Read a txt file by URL link in MATLAB


I have a txt file in the following URL path:

https://www.dropbox.com/s/zz9qp06fykz4otw/Counter.txt

I wana read it into MATLAB. This file contains only an integer value. I used fopen() function, but it gives me error:

The file name contains characters that are not contained in the filesystem encoding. Certain operations may not work as expected.

Then, I used webread() and urlread(), but a big file is generating and not working as expected.

Is there any suggestion to how to read a simple value from an URL link?


Solution

  • It is because the url https://www.dropbox.com/s/zz9qp06fykz4otw/Counter.txt refers to the dropbox page and not the file. If you add ?dl=1 at the end of the link, then it will refer to the file instead. e.g.

    data = urlread('https://www.dropbox.com/s/zz9qp06fykz4otw/Counter.txt?dl=1')
    
    data =
    
        '100'