Why does it not plot the values
2 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!