
Quiver Plot from matrices
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Rasmus Hvidberg
il 2 Apr 2019
Commentato: Franciszek Aniol
il 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 Commenti
Risposta accettata
Cris LaPierre
il 4 Apr 2019
Modificato: Cris LaPierre
il 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 Commento
Franciszek Aniol
il 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".
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Vector Fields in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!