graphics - Matlab -plot a vector field -
i have written function in matlab gives me vector @ position (x,y,z).
now looking easiest way make colored map of field on grid , color should related norm of vector.
what easiest way define such grid $x \in [x_0,x_1],y \in [y_0,y_1], z \in [z_0,z_1]$? linspace each component possible, maybe there command gives me grid.
now need evaluate function. problem is, gives me 2 vectors, interested in first one. when first tried thought $[a(i,j,k),~]=function(x(i),y(j),z(k))$ work, did not(my goal was: choose first vector(a) , mark him reference(i,j,k), later on know coordinates vector belongs to).
so highly interested in kind of ideas.
instead of
[a(i,j,k),~]=function(x(i),y(j),z(k));
try
[a(i,j,k,:),~]=function(x(i),y(j),z(k));
so can fit entire size of 3-coordinate vector. also, if want preallocate space use
= zeros(nx,ny,nz,3);
where nx,...
dims of coordinate space. @moly explains, use meshgrid
generate 3d grid,
[x y z] = meshgrid(x,y,z);
and loop or vectorize resolve values of function @ points x(i,j,k),y(i,j,k),z(i,j,k)
, compute norm
, store in 3d array c
.
edit
representing cube mesh(x,y,z,c)
not possible individual slices of 3d cube can visualized mesh
, setting height z
equal result of function c
. additional work required coloring right.
yet alternative use pcolor
or contourf
. perhaps easiest way show 4d data beyond creating 3d isosurface.
code:
figure colormap(jet) ii=1:9 subplot(3,3,ii) pcolor(x(:,:,ii),y(:,:,ii),f(:,:,ii)) axis('equal','square'), title(['z=' num2str(ii)]) caxis([0 1]) end
Comments
Post a Comment