Why is this happening in this code?

1 回表示 (過去 30 日間)
alpedhuez
alpedhuez 2022 年 3 月 12 日
コメント済み: alpedhuez 2022 年 3 月 12 日
baseurl = "https://www.somecompany.com/xml/";
datelimits = datetime({'20080401', '20080501'}, 'InputFormat', 'yyyyMMdd','Format','yyyyMMdd');
subfile_limit = 5; %no more than _5 -- adjust as appropriate
subfile_modifier = ["", "_" + (1:subfile_limit)] + ".xml";
for Day = datelimits(1):datelimits(2)
daystr = string(Day);
for Sub = subfile_modifier
filename = "A_" + daystr + Sub;
url = baseurl + filename;
try
outfilename = websave(filename,url);
fprintf('fetched %s\n', filename);
catch
break; %skip remaining subfiles for this date upon first failure
end
end
end
Then I got the following value for "subfile_modifier"
But the following for "Sub"
I do not understand why "_' + (1:subflie_limit) part is missing. Please advise.

採用された回答

Cris LaPierre
Cris LaPierre 2022 年 3 月 12 日
The ".xml" corresponds to the "" in your submifle_modifier.
subfile_limit = 5;
subfile_modifier = ["","_" + (1:subfile_limit)] + ".xml"
subfile_modifier = 1×6 string array
".xml" "_1.xml" "_2.xml" "_3.xml" "_4.xml" "_5.xml"
If you do not want to use that extension, then remove the "".
subfile_modifier = ["_" + (1:subfile_limit)] + ".xml"
subfile_modifier = 1×5 string array
"_1.xml" "_2.xml" "_3.xml" "_4.xml" "_5.xml"
  1 件のコメント
alpedhuez
alpedhuez 2022 年 3 月 12 日
Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by