function hout = quiverColor(h) cmap = hsv(360);% color based on direction theta = atan2(get(h,'VData'),get(h,'UData')); ti = round((theta+pi)/(2*pi) * (length(cmap)-1) + 1);% normalized and indexed to colormap % pv = repmat(ti,1,3)'; ti(isnan(ti)) = 1;% don't worry about color of nans cuz x,ydata is nan. won't show ti = cmap(ti,:); % These are the fields which will be copied. Add in what you want. All % bets are off. I would just use 'copyobj', but it is not a perfect copy % for quivergroup objects. It misses the XYZUVW data, although the % children retain it :( xFields = {'XData','YData','ZData','UData','VData','WData'}; fFields = {'AutoScale','AutoScaleFactor'}; xF = get(h,xFields); fF = get(h,fFields); % Clear empty fields: for n = 1:length(xFields), cli(n) = isempty(xF{n}); end xFields(cli) = []; xF(cli) = []; % How many vectors and their size for n = 1:length(xFields), dim{n} = size(xF{n}); nm(n) = prod(dim{n}); end if any(diff(nm)) error('need to add functionality for different XYZ') end hp = get(h,'Parent'); hpn = get(hp,'NextPlot'); set(hp,'NextPlot','add') set(h,'Visible','off') N = max(nm); disp('generating individual quivers.....') for n = 1:N hout(n) = quiver(hp,0,0,'Color',ti(n,:)); set(hout(n),fFields,fF) for m = 1:length(xF) set(hout(n),xFields{m},xF{m}(n)) end end delete(h) return figure, f = @()rand(20,1)-.5; h = quiver(f(),f(),f(),f()); h = quiverColor(h); % hc = get(h,'Children');% get quivergroup children (the actual arrows) % % hc(1): shaft N*3 % % hc(2): head N*4 % % hc(3): dunno, can't see it. N*1