导入数据和调用功能

时间:2014-04-26 14:34:48

标签: matlab matlab-figure

我如何使用功能" is_double_url"要检查保存在文件名中的700个数据" training_URL",我只能在cmd窗口中查看数据或输入" is_double_url(' www.google.com')& #34;在f10.m.但我想使用如下所示的导入数据来调出函数并检查700数据

is_double_url.m文件

function out = is_double_url(url_path1)

if url_path1(end)~='/'
url_path1(end+1)='/';
end

url_path1 = regexprep(url_path1,'//','//www.');
url_path1 = regexprep(url_path1,'//www.www.','//www.');

f1 = strfind(url_path1,'www.');
if numel(f1)<2
out = false;
else
f2 = strfind(url_path1,'/');
f3 = bsxfun(@minus,f2,f1');

count_dots = zeros(size(f3,1),1);
for k = 1:size(f3,1)
    [x,y] = find(f3(k,:)>0,1);
    str2 = url_path1(f1(k):f2(y));
    if ~isempty(strfind(str2,'..'))
        continue
    end
    count_dots(k) = nnz(strfind(str2,'.'));
end
out = ~any(count_dots(2:end)<2);

if any(strfind(url_path1,'://')>f2(1))
    out = true;
end
end

return;

f10.m文件

url_path1 = importdata('DATA\URL\training_URL')
out = is_double_url(url_path1)

enter image description here

1 个答案:

答案 0 :(得分:1)

注意数字(。)条件的变化:

function out = is_double_url(url_path1)

if url_path1(end)~='/'
    url_path1(end+1)='/';
end

url_path1 = regexprep(url_path1,'//','//www.');

url_path1 = regexprep(url_path1,'//www.www.','//www.');

f1 = strfind(url_path1,'www.');
if numel(f1)>2                  % changed it here
    out = false;
else
    f2 = strfind(url_path1,'/');
    f3 = bsxfun(@minus,f2,f1');

    count_dots = zeros(size(f3,1),1);
    for k = 1:size(f3,1)
        [x,y] = find(f3(k,:)>0,1);
        str2 = url_path1(f1(k):f2(y));
        if ~isempty(strfind(str2,'..'))
            continue
        end
        count_dots(k) = nnz(strfind(str2,'.'));
    end
    out = ~any(count_dots(2:end)<2);

    if any(strfind(url_path1,'://')>f2(1))
        out = true;
    end
end

if ~out  % I'm not sure if this is what you want..
out=-1;
end

return;

关于你在评论中提到的问题,让我们说url_path1是一个大小为700x1的单元格数组;然后(我想)你可以说

out=[];
for i=1:size(url_path1,1)
  out=cat(2,out,is_double_url(url_path1{i,1}));
end