Quiver Plot from matrices

조회 수: 6 (최근 30일)
Rasmus Hvidberg
Rasmus Hvidberg 2019년 4월 2일
댓글: Franciszek Aniol 2022년 4월 27일
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