
Quiver Plot from matrices
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Rasmus Hvidberg
le 2 Avr 2019
Commenté : Franciszek Aniol
le 27 Avr 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 commentaires
Réponse acceptée
Cris LaPierre
le 4 Avr 2019
Modifié(e) : Cris LaPierre
le 4 Avr 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 commentaire
Franciszek Aniol
le 27 Avr 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".
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Vector Fields dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!