Why does it not plot the values

조회 수: 8 (최근 30일)
sparsh garg
sparsh garg 2021년 9월 1일
댓글: Walter Roberson 2021년 9월 1일
So let's say you have smoe X and Y.
let's say you have a set of indices in another array called flag
now when i do this
plot(X(flag),Y(flag)
,a nice plot is displayed
but when I do
A=[X(flag),Y(flag)];
and then do
plot(A(1,:),A(2,:))
the plot doesn't show.
Any ideas why this is happening?

채택된 답변

Walter Roberson
Walter Roberson 2021년 9월 1일
When X is a row vector and Y is a row vector, and flag is a vector, then regardless of whether flag is a row vector or a column vector, the output of X(flag) will be a row vector and the output of Y(flag) would be a row vector. When you did [X(flag, Y(flag)] then that would be concatenating together two row vectors horizontally, and the result would be a row vector. Your plot attempt A(2,:) would then be trying to use row 2 of a row vector, which would not exist, and you would get an error
When X is a column vector and Y is a column vector, and flag is a vector, then regardless of whether flag is a row vector or a column vector, the output of X(flag) will be a column vector and the output of Y(flag) would be a column vector. When you did [X(flag, Y(flag)] then that would be concatenating together two column vectors horizontally, and the result would be a something-by-2 matrix. Your plot attempt A(1,:), A(2,:) would then be extracting row 1 of the matrix with 2 columns, to plot against row 2 of the matrix with 2 columns. That would draw a single line segment from (x(1),x(2)) to (y(1),y(2)) instead of the (x(1),y(1)) to (x(2),y(2)) that you would have expected.
You did not mention any error message, so that tends to suggest that your X and Y are both column vectors. In that case, what you should be doing is
plot(A(:,1),A(:,2))
  댓글 수: 2
sparsh garg
sparsh garg 2021년 9월 1일
tried doing that now gives me indice exceeds matrix dimension
X_pts=[edges2.x,edges.y];
X_pts = unique(X_pts,'rows');
x=X_pts(:,1);
y = X_pts(:,2);
FP1=[x(marker);y(marker)];
figure(1);
plot(x(marker),y(marker))
set(gca,'YDir','reverse')
figure(2);
plot(FP1(:,1),FP1(:,2));
Walter Roberson
Walter Roberson 2021년 9월 1일
You said in your question that you were doing
A=[X(flag),Y(flag)];
but in your actual code we see
FP1=[x(marker);y(marker)];
The difference between that comma compared to the semi-colon is important !!
I will have a look later after I get some sleep.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by