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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by