
Quiver Plot from matrices
6 views (last 30 days)
Show older comments
Rasmus Hvidberg
on 2 Apr 2019
Commented: Franciszek Aniol
on 27 Apr 2022
I have a problem making a arrow-like plot from 2 matrices.
Suppose I have 2 matrices, each filled with zeros, except for at certain positions. like the below:
xComponent = zeros(5,5)
xComponent(3,3) = 1
yComponent = zeros(5,5)
yComponent(3,3) = 2
I now have 2 matrices, one containing the x-component of the "arrow" that I want plotted, and the other containing the y-component. What I was for is to make a "plot" of the 5x5 grid, with an arrow, originating in the point (3,3), with an x-component of 1 and y-component of 2.
The below is a crude image, portraying what I am trying to accomplish.

I have much larger matrices with much more values, but I feel confident that I can make it work on a large scale, if I can just make it work with this.
I do NOT want to explicitly give quiver() the values it needs, I want to somehow generalize it, so that quiver(), or a function like it, can grab the values directly from the matrices and make an arrow-plot.
Thanks!
0 Comments
Accepted Answer
Cris LaPierre
on 4 Apr 2019
Edited: Cris LaPierre
on 4 Apr 2019
What do you mean by not wanting to give quiver the values it needs? Not sure how you would create the plot without doing that. Here's how I would recreate your plot.
xComponent = zeros(5,5);
xComponent(3,3) = 1;
yComponent = zeros(5,5);
yComponent(3,3) = 2;
[Y,X]=meshgrid(1:size(xComponent,1),1:size(xComponent,2));
figure
plot(X,Y,'k.','MarkerSize',10)
hold on
quiver(X,Y,yComponent,-xComponent,2)

1 Comment
Franciszek Aniol
on 27 Apr 2022
I think the person meant that instead of writing this:
quiver(X,Y,yComponent,-xComponent,2)
the option would be
M = [X,Y,yComponent,-xComponent,2]
quiver(M)
It's just an assumption that this was meant under "not wanting to give quiver the values it needs".
More Answers (0)
See Also
Categories
Find more on Vector Fields in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!