From octave-sources-request at bevo dot che dot wisc dot edu Tue May 16 11:48:50 2000 Subject: Plotting vectors function, Matlab's "quiver" From: roberto at calvin dot ocfis dot furg dot br To: octave-sources at bevo dot che dot wisc dot edu Date: Thu, 28 Oct 1999 00:00:07 -0200 (EDT) --8323328-1804289383-941076020=:844 Content-Type: TEXT/plain; CHARSET=US-ASCII Hi, I've done a function that plots vectors, just like the "quiver" function in Matlab. I don't know if here's the right place to send it. It's pretty simple, but works well. Roberto -- (o- Roberto A. F. Almeida //\ ralmeida at email dot com V_/_ "Uncle Cosmo ... why do they call this a word processor?" "It's simple, Skyler ... you've seen what food processors do to food, right?" -- MacNelley, "Shoe" --8323328-1804289383-941076020=:844 Content-Type: TEXT/plain; CHARSET=US-ASCII Content-Description: quiver.m ## Copyright (C) 1996 John W. Eaton ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2, or (at your option) ## any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, write to the Free ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA ## 02111-1307, USA. ## usage: quiver (u, v, x, y) ## ## Plot the (u,v) components of a vector field in a (x,y) meshgrid. ## ## You can try: ## ## a = b = 1:10; ## [x,y] = meshgrid(a,b); ## u = rand (10,10); ## v = rand (10,10); ## quiver(u,v,x,y) ## ## See also: plot, semilogx, semilogy, loglog, polar, mesh, contour, ## bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title ## Author: Roberto A. F. Almeida (roberto at calvin dot ocfis dot furg dot br) function quiver (u, v, x, y) if (nargin != 4) usage ("quiver (u, v, x, y)"); endif if ((rows (u) != rows (v)) || (columns (u) != columns (v))) error ("u, v, x and y must all have the same size."); endif if ((rows (x) != rows (y)) || (columns (x) != columns (y))) error ("u, v, x and y must all have the same size."); endif if ((rows (u) != rows (x)) || (columns (u) != columns (x))) error ("u, v, x and y must all have the same size."); endif ## Calculating the grid limits. minx = min (min (x)); maxx = max (max (x)); miny = min (min (y)); maxy = max (max (y)); max_arrow = max ( [max (max (u)) , max (max (v)) , abs (min (min (u))) , abs (min (min (v)))] ); border = max_arrow * 1.2; limits = [ minx - border, maxx + border, miny - border, maxy + border ]; axis (limits); ## Ok, now plot the arrows. lenx = columns (x); leny = rows (y); gset noarrow; gplot 0 title ""; for j = 1:lenx for i = 1:leny command = sprintf ("gset arrow from %f,%f to %f,%f", x(i,j),y(i,j),x(i,j)+u(i,j),y(i,j)+v(i,j)); eval (command); endfor endfor replot; endfunction --8323328-1804289383-941076020=:844-- ----------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.che.wisc.edu/octave/octave.html How to fund new projects: http://www.che.wisc.edu/octave/funding.html Subscription information: http://www.che.wisc.edu/octave/archive.html -----------------------------------------------------------------------