2014-04-09 6 views
0

내 목적은 다음 부분으로 문자열을하게 분할 'f11_data가'그 분할 단어를 포함하고 있는지 여부를 확인하는 것입니다 파일을 반복. 그렇다면, 0을 반환하고, 그렇지 않으면 1을 반환합니다. 저는 100 개의 문자열을 가지고 있지만, 코드 타임에 str/needles 100을 입력하는 것은 의미가 없습니다. 어떻게 루핑을 사용합니까? importdata을 사용하는 중에 문제가 있습니다. 데이터 가져 오기 및

data = importdata('URL') 
needles = regexp(data,'[:/.]*','split') %// note the different search string 

for i = 1:2 

A11_data = needles{i}; 
data2 = importdata(strcat('f11_data', int2str(i))); 
%feature11_data=(~cellfun('isempty', regexpi(data2, needles, 'once'))) 
%feature11(i)=feature11_data 
~cellfun('isempty', regexpi(data2, needles, 'once')) 
end 

내가 오류 얻을 : 내가 루프를 사용하여 위의 코드를 수정하는 방법
str1  = 'http://en.wikipedia.org/wiki/hostname'; 
str2  = 'http://hello/world/hello'; 
str3  = 'http://hello/asd/wee'; 

f11_data1 = 'hostname From wikipedia, the free encyclopedia Jump to: navigation, search In computer networking, a hostname (archaically nodename .....'; 
f11_data2 = 'hell'; 
f11_data3 = 'hello .....'; 

needles1 = strcat('\<', regexpi(str1,'[:/.]*','split'), '\>') 
needles2 = strcat('\<', regexpi(str2,'[:/.]*','split'), '\>') 
needles3 = strcat('\<', regexpi(str3,'[:/.]*','split'), '\>') 

~cellfun('isempty', regexpi(f11_data1, needles1, 'once')) 
~cellfun('isempty', regexpi(f11_data2, needles2, 'once')) 
~cellfun('isempty', regexpi(f11_data3, needles3, 'once')) 

은 사용 " ??? 오류 ==> regexpi regexpi의 모든 세포는해야합니다 문자열.

Error in ==> f11_test2 at 14 
~cellfun('isempty', regexpi(haystack, needles, 'once')) " 
+0

내부'f11_data1'와'f11_data2'는 무엇입니까? 'data2'는 문자열입니까? – Deve

+0

f11_data1는 f11_data2는 f11_data3는 URL.txt이 STR1, STR2, STR3를 포함하면서 – user3340270

답변

0

그것은 당신이 뭔가에 상응를 수행하려는 경우,하지만 당신이 뭘 하려는지 알 어렵다

for i = 1:3 
    str = importdata(URL_LIST[i]) 
    needle = strcat('\<', regexp(str,'[:/.]*','split'), '\>'); 

    haystack = importdata(HAYSTACK_LIST[i]); 
    ~cellfun('isempty', regexpi(haystack, needle, 'once')) 
end 

분명히 URL_LISTHAYSTACK_LIST을 정의해야합니다.

+0

내 목적은 다음 부분으로 문자열을하게 분할 'f11_data가'그 분할 단어가 포함 된 여부를 확인하는 것입니다 각각 haystack1, haystack2, haystack3입니다. 그렇다면 then 0을 반환하고 no이면 1을 반환합니다. – user3340270

+0

yes 그렇기 때문에 위의 코드를 수정하여 URL 목록과 f11_data를 가져와야합니다. – ysakamoto

+0

먼저 1 개의 데이터를 사용해보고 싶습니다. importdata와 "str = 'http : //en.wikipedia.org/wiki/hostname'사이에 다른 것이 있습니다."; ,하지만 난 그것을 IMPORTDATA를 사용하는 경우 나 1x1cells 보여 1x6cells에 내 데이터를 분할 CNT; "STR을 'http://en.wikipedia.org/wiki/hostname'="사용할 때 나는 1x6cells에 내 데이터를 분할 할 수 있습니다. 어떤 아이디어? – user3340270

관련 문제