Splitting a long string into individual variables

조회 수: 7 (최근 30일)
Calvin Spangler Young
Calvin Spangler Young 2019년 2월 6일
댓글: Calvin Spangler Young 2019년 2월 6일
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
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일
"... 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일
@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개)

카테고리

Help CenterFile Exchange에서 Import Data에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by