<div dir="ltr"><div>Hi all,<br><br></div>So I coded something that could perhaps be useful to others. It grows a patch around a seed up to a certain distance. See below<br><br>function [list] = mesh_patch(mesh,seed,dmax)<br><br>% [list] = mesh_patch(mesh,seed,d)<br>% <br>% return the list of connected vertices that are at most d mesh.unit away<br>% from seed.<br>%<br>% Maximilien Chaumon 2018<br><br>% measure distance to seed<br>seedpos = mesh.pos(seed,:);<br>distances = sqrt(sum(bsxfun(@minus,mesh.pos,seedpos).^2,2));<br><br>% crawl starting from seed<br>list = crawl(mesh.tri,distances,dmax,seed);<br><br><br>function final = crawl(tri,d,dmax,vert)<br><br>% bookkeeping: the list of vertices<br>persistent listi<br>st = dbstack;<br>level = sum(strcmp({<a href="http://st.name">st.name</a>},'crawl'));<br>if level == 1<br>    listi = [];<br>end<br>%<br><br>listi(end+1) = vert; % append this vertex to the list<br><br>conn = tri(any(tri==vert,2),:);% connected vertices<br>conn = unique(conn);<br>conn(d(conn) > dmax) = []; % remove those that are too far.<br>conn(ismember(conn,listi)) = [];%keep only vertices that have not been crawled yet<br>for i = 1:numel(conn)<br>    crawl(tri,d,dmax,conn(i));% move to next <br>end<br><br>% bookkeeping: return the list at last<br>if level == 1<br>    final = listi; % return list if it's last call<br>end<br><br><br><br><br><br><br><br></div><br><div class="gmail_quote"><div dir="ltr">Le ven. 13 avr. 2018 à 16:16, Maximilien Chaumon <<a href="mailto:maximilien.chaumon@gmail.com">maximilien.chaumon@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Dear all,<br><br></div>I'm trying to extract a connected patch of vertices at most say 2 cm away from a given seed.<br></div>Is there an easy way to do this in FieldTrip?<br><br></div>Many thanks,<br></div>Max<br></div></blockquote></div>