Hello--
I've got a long string of websites that looks like this:
"https://stgeorge"
"https://stjoseph"
"https://stlouis"
I've got them all as a string in variable X. I'm trying to use them with the webread command which requires that they be individual, so I'm looking for a way to split them all into their own variables or otherwise produce a way which I can collect data from all of the sites.
Any help is much appreciated! thanks!

4 件のコメント

madhan ravi
madhan ravi 2019 年 2 月 6 日
What‘s your expected result? State it explicitly to avoid confusions.
Walter Roberson
Walter Roberson 2019 年 2 月 6 日
Do you mean that you have aa nonscalar string object ? Or aa character vector with aa delimiter ?
KSSV
KSSV 2019 年 2 月 6 日
IS your vaiable a cell? If so you can use X{1} ..etc.
Calvin Spangler Young
Calvin Spangler Young 2019 年 2 月 6 日
I believe I have a nonscalar string. I'm trying to build something with which can pull data off of craigs list for a stats project on average prices in different places.
Expected result:
Something which allows me to do the following:
webread('https://stgeorge.craigslist.org')
webread('https://stjoseph.craigslist.org')
webread('https://stlouis.craigslist.org')
Is there some way to reference each line in a string differently? Or otherwise handle this without typing out all of the different sites?

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

 採用された回答

Stephen23
Stephen23 2019 年 2 月 6 日
編集済み: Stephen23 2019 年 2 月 6 日

0 投票

"... so I'm looking for a way to split them all into their own variables"
That would not be a good approach. Read this to know why:
"or otherwise produce a way which I can collect data from all of the sites."
Sure, that is easy! Just use a loop and basic, efficient indexing:
S = ["https://stgeorge", "https://stjoseph", "https://stlouis"];
N = numel(S);
C = cell(1,N);
for k = 1:N
C{k} = webread(S(k));
end

4 件のコメント

madhan ravi
madhan ravi 2019 年 2 月 6 日
If so couldn't it be like:
C=arrayfun(@(x) webread(x),S,'un',0)
Just curious.
Stephen23
Stephen23 2019 年 2 月 6 日
編集済み: Stephen23 2019 年 2 月 6 日
@madhan ravi: you are right, that should also work (but I have not tried it). Also:
C = arrayfun(@webread, S,'uni',0)
madhan ravi
madhan ravi 2019 年 2 月 6 日
@Stephen Cobeldick: thanks for clarifying.
Calvin Spangler Young
Calvin Spangler Young 2019 年 2 月 6 日
Thanks! Appreciate the help, this looks like it'll work great

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Get Started with MATLAB についてさらに検索

製品

リリース

R2018b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by