How to create a vectorfield?

5 views (last 30 days)
Peter
Peter on 11 Dec 2012
Hi everyone,
I would like to create a cube with vectors as elements, let's say a vector field of unit vectors e.i. length one. Is this possible and how is it done? Thanks for your input.
Best, Peter

Answers (2)

Sean de Wolski
Sean de Wolski on 11 Dec 2012
Edited: Sean de Wolski on 11 Dec 2012
doc meshgrid
doc quiver3
doc coneplot
Not sure of the details of what you want but it's likely some combination of the above.
More
Yes, you would use meshgrid for this:
The meshgrid would generate the coordinate matrices or rather the base of your vectors. Then you would need three more matrices of equal size that would be the components.
Here is an example that draws one unit vector at (0,0,0) pointing up and to the right with unit length:
s = fzero(@(s)1-sqrt((s^2)*3),1);
quiver3(0,0,0,s,s,s)
Now if you wanted it for the full thing, you could use s, repmat-ed to be the size of the output from meshgrid, etc.

Peter
Peter on 11 Dec 2012
Hi Sean,
I'm pretty sure this will become handy at some point but right now I'm not so worried about plotting a vector field but creating one. Or is meshgrid really what I'm looking for?
I'd like to have a let's say 10x10x10 matrix and fill each cell with vectors pointing upwards, length one.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!