matlab - import data and Looping for the file -
my purpose split string part check whether 'f11_data' contain split word. if yes return 0, if no return 1. have 100 strings, doesn't make sense type str/needles 100 inside code times. how use looping that? i'm facing problem using importdata
.
str1 = 'http://en.wikipedia.org/wiki/hostname'; str2 = 'http://hello/world/hello'; str3 = 'http://hello/asd/wee'; f11_data1 = 'hostname wikipedia, free encyclopedia jump to: navigation, search in computer networking, 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'))
this how modified above code using loop:
data = importdata('url') needles = regexp(data,'[:/.]*','split') %// note different search string = 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
i error : " ??? error using ==> regexpi cells regexpi must strings.
error in ==> f11_test2 @ 14 ~cellfun('isempty', regexpi(haystack, needles, 'once')) "
it's hard tell trying but, if want equivalent,
for = 1:3 str = importdata(url_list[i]) needle = strcat('\<', regexp(str,'[:/.]*','split'), '\>'); haystack = importdata(haystack_list[i]); ~cellfun('isempty', regexpi(haystack, needle, 'once')) end
obviously need define url_list
, haystack_list
.
Comments
Post a Comment