Why does it not plot the values
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
sparsh garg
el 1 de Sept. de 2021
Comentada: Walter Roberson
el 1 de Sept. de 2021
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 comentarios
Respuesta aceptada
Walter Roberson
el 1 de Sept. de 2021
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 comentarios
Walter Roberson
el 1 de Sept. de 2021
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!