www.gusucode.com > robotexamples 工具箱 matlab源码程序 > robotexamples/ros/helpers/exampleHelperGazeboListModels.m
function modelList = exampleHelperGazeboListModels() %exampleHelperGazeboListModels - Generates a list of all models in the Gazebo Simulation % L = exampleHelperGazeboListModels() Returns a list of models in the current Gazebo % simulation. It takes no arguments. % Copyright 2014 The MathWorks, Inc. page = urlread('http://gazebosim.org/models/'); content = regexp(page, ['.*?<table' '(.*?)</table'], 'tokens'); content = content{1}{1}; rowind = 0; rows = regexpi(content, '<tr.*?>(.*?)</tr>', 'tokens'); for i = 1:numel(rows) colind = 0; if (isempty(regexprep(rows{i}{1}, '<.*?>', ''))) continue else rowind = rowind + 1; end headers = regexpi(rows{i}{1}, '<th.*?>(.*?)</th>', 'tokens'); if ~isempty(headers) for j = 1:numel(headers) colind = colind + 1; data = regexprep(headers{j}{1}, '<.*?>', ''); if (~strcmpi(data,' ')) out{rowind,colind} = strtrim(data); %#ok<AGROW> end end end cols = regexpi(rows{i}{1}, '<td.*?>(.*?)</td>', 'tokens'); for j = 1:numel(cols) if(rowind==1) if(isempty(cols{j})) continue else colind = colind + 1; end else colind = j; end data = regexprep(cols{j}{1}, ' ', ' '); ismodel = regexp(cols{j}{1},'DIR', 'once'); data = regexprep(data, '<.*?>', ''); if isempty(ismodel) && (colind == 1) rowind = rowind - 1; break; end if (~isempty(data)) out{rowind,colind} = strtrim(data) ; end end end col2 = cellfun(@(x) x, out(3:end,2),'UniformOutput', false); modelList = cellfun(@(x) x(1:end-1), col2,'UniformOutput', false); end