« Teaching Geoscience with MATLAB Interest Group

'webread' for ingesting data  

This post was edited by Sarah Nakamoto on Jan, 2021
Hi All:

When Frederik shared his revelation on publish, he opened my eyes to webread.m to bring in data directly to workspace. His example used a .csv file, which webread brings in beautifully (although I'm not sure how it assigns those field names to the structure 'w'). However, when I try webread on the following ascii file:


it brings it in as a long string (~83 kilocharacters), that needs to be parsed, reshaped, and converted (str2num), to work with numeric values. I just want a flag that tells MATLAB (webread) to expect the data to come in as double-precision numbers, not a long continuous string. I've looked up the documentation for webread and weboptions, but I didn't see a straightforward solution here. Anybody experienced with this who can point out my (dumb) mistake?



Share edittextuser=29480 post_id=25262 initial_post_id=0 thread_id=7652

This post was edited by Sarah Nakamoto on Jan, 2021

Try to read it into a table instead:


though I note it will right now bring it into a table that is NX1 with 3 columns in the column itself. You can then extract the data into a double, turn it into 3 separate vectors, turn it into a 3 column table, ... Your choice.



Share edittextuser=29492 post_id=25265 initial_post_id=0 thread_id=7652

but I also am having trouble - running into a bug. Trying to work around it now...


Share edittextuser=29492 post_id=25268 initial_post_id=0 thread_id=7652

This post was edited by Sarah Nakamoto on Jan, 2021
Here's the code I got to work:

options = weboptions('ContentReader',@(fn)readtable(fn, 'Format','%f %f %f',...
w=webread(www.essie.ufl.edu/~arnoldo/ocp6168/homework/lapreg.dat, options);

varnames = {'DayofYear', 'east', 'north'};
w.Properties.VariableNames = varnames;


Share edittextuser=29492 post_id=25271 initial_post_id=0 thread_id=7652

By the way, a great example using this is on my blog - written by my colleague, Kelly.


He makes good use of ContentReader. Check it out.


Share edittextuser=29492 post_id=25274 initial_post_id=0 thread_id=7652

Join the Discussion

Log in to reply

« Teaching Geoscience with MATLAB Interest Group