Adding repetitive number to web address.
1 回表示 (過去 30 日間)
古いコメントを表示
Muhammad Qaisar Fahim
2022 年 3 月 17 日
コメント済み: Walter Roberson
2022 年 3 月 18 日
n=100;
for k=1:1:n
B(k)=Locs(1,k)
C(k)=Locs(2,k)
r2(i)=webread('https:/........=B(i), C(i)');
end
In the above code I want to extract each value in Locs matrix and for each pair of value i.e., B and C I want to automatically calculate r2(i) which is basically calling a webside. When I code it like this to automatically use the values of B(i) and C(i) it gives me below mentioned error. But when I input values manually and calculate it works fine. I think there is an issue with the way I am giving B(i) and C(i) in the website. Please correct me.
Error using matlab.internal.webservices.HTTPConnector/copyContentToByteArray (line 373)
The server returned the status 400 with message "Bad Request" in response to the request to
URL https:.....
Error in readContentFromWebService (line 46)
byteArray = copyContentToByteArray(connection);
Error in webread (line 125)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
0 件のコメント
採用された回答
Walter Roberson
2022 年 3 月 18 日
r2(k) = webread( "https:/........=" + B(k) + ", " + C(k));
assuming that the syntax is something followed by a literal equal sign, followed by the content of B(k), followed by a comma and then space, then the content of C(k)
Caution: it is uncommon for spaces to appear in URLs. When they do appear, they often have to be encoded as %20
6 件のコメント
Walter Roberson
2022 年 3 月 18 日
baseurl = "https://abc.xyz.org/a1/mem21m?sites="
B = randi([-90 90], 1, 5)
C = randi([-90 90], 1, 5)
for k = 1 : length(B)
thisurl = baseurl + B(k) + ", " + C(k)
result{k} = webread(thisurl)
end
And that is why I did not use webread(): I knew it would generate an error on the first attempt, so you would have seen only one example URL (because the error would have prevented the other example URL from being constructed.) As Steven indicates, the problem you were having trouble with was the text manipulation.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!