How can I invert the position of a vector?

1 view (last 30 days)
In the following code I'm trying to invert the position of vector "y"; I'm expecting to pass from something like this y=[a b c d] to y=[d c b a], and I don't know how can I plot the result for this two vectors.
The code is shown next
%close everything and clear everything
close all;
clear all;
clc;
% First we read an image wich must contain a graphic in it and then convert it to black and white
A=im2bw(imread('prueba3.png'));
%Show the image
figure();
imshow(A);
%Obtain the rows and columns
[F,U]=size(A);
i=1;
%Then we "swap" the matrix looking for the black pixels defined by a 0 and save the
%position "(F,U)" in the vector "x" and "y"
for n=1:U;
for m=1:F;
if A(m,n)~=1;
x(i)=n;
y(i)=m;
else
m=m+1;
end
end
n=n+1;
i=i+1;
end
%How can I invert the positions of the "y" vector and then plot(x,y) even
%though it changed the dimension of y vector?
figure();
plot(x,y);
The Image I've been using is this
The resultant graphic I'm getting is shown as figure 2:
In wich we can see that the vector "y" is inverted
I'm also looking for the 0 generated in y(0,0)
Thank you so much for your help!

Accepted Answer

Walter Roberson
Walter Roberson on 2 May 2018
Easiest way:
set(gca, 'YDir', 'reverse')

More Answers (0)

Categories

Find more on Specialized Power Systems in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!