Editing Text Strings through Looping

5 ビュー (過去 30 日間)
James Higgins
James Higgins 2020 年 10 月 28 日
回答済み: Geoff Hayes 2020 年 11 月 10 日
Hello Matlab community,
I am new to Matlab programming and have a question surrounding editing text strings through looping.
I am working with API datasearch tool and would like to loop through various text strings. How would I go about doing this?
For example, below is standard Matlab API code for a nonexistant website example. In this example I am telling Matlab to collect from this website a specific data array with code=587. Then I move onto the next code=612.
api = 'http://examplewebsite.com/api'
url = [api 'max=1000/type=fl/sign=xy/code=587/st=87']
S = webread(url)
api = 'http://examplewebsite.com/api'
url = [api 'max=1000/type=fl/sign=xy/code=612/st=87']
S = webread(url)
If I had a list of codes I wanted Matlab to collect data for, such as
d = [587 612 876 296 137 635 591]
Could I create a loop where all I change to the string 'max=1000/type=fl/sign=xy/code=587/st=87' is just the code=587 to code=612...up to 591?
The goal would be to get 7 different S matrices corresponding to the 7 codes in one step.
Thank you,
James

回答 (1 件)

Geoff Hayes
Geoff Hayes 2020 年 11 月 10 日
James - you could use sprintf to create your url with the "code"
for code = [587 612 876 296 137 635 591]
url = sprintf('http://examplewebsite.com/apimax=1000/type=fl/sign=xy/code=%d/st=87', code)
S = webread(url);
% save S to larger matrix or cell array
end

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by