Is there a built-in way to build a GET url in Matlab from a set of parameters?
10 visualizaciones (últimos 30 días)
Ricardo el 1 de Feb. de 2013
0 down vote favorite
I'm trying to get data using an API that takes GET requests. The data are returned in XML format, so I'm hoping to use the xmlread function, which can take a URL as input. However, because the data comes from an API, I need to build the URL with the GET request's arguments and use that as the input for xmlread.
I don't want to use the urlread and urlwrite functions for these reasons:
1. If I use urlread, I get the data as a string, which can't be passed into xmlread.
2. If I use urlwrite, I have to write the data to a file and read it in from there, using xmlread, which is horribly inefficient when my functions make hundreds of API calls.
Is there a built-in Matlab function that allows me to pass in a URL and a cell array (or some other data type) of (argument_name, value) pairs and build a get URL from that? I'm assuming that if a canned method exists in basic Matlab, it will be more efficient than me writing my own that will be rife with string concatenation.
Cedric Wannaz el 1 de Feb. de 2013
Editada: Cedric Wannaz el 1 de Feb. de 2013
If you just want to build a string from multiple components, you can use sprintf, e.g.
>> v = 3 ;
>> subfolder = 'WWW' ;
>> s = sprintf('GET http://www.w%d.org/pub/%s/', v, subfolder)
The formatSpec of sprintf will provide you with a lot of flexibility.
>> doc sprintf