Quiver Plot from matrices

6 次查看(过去 30 天)
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.
crudeImage.png
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!

采纳的回答

Cris LaPierre
Cris LaPierre 2019-4-4
编辑:Cris LaPierre 2019-4-4
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 个评论
Franciszek Aniol
Franciszek Aniol 2022-4-27
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".

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by