How can I flip this line upside down:
This is my code that may not need flipud() :
x = [1 2 3];
y = [2 2.5 3.5];
flipud(plot(x,y))

3 commentaires

Adam
Adam le 2 Fév 2017
The result of the plot instruction is a handle to the graphics object which is a scalar 'Line' object. Flipping this will do nothing at all!
Ezz El-din Abdullah
Ezz El-din Abdullah le 2 Fév 2017
Why is the 'line' a scalar object not an array?
Adam
Adam le 2 Fév 2017
Modifié(e) : Adam le 2 Fév 2017
Because it is a line object. There is only one line. Of course, it depends what version of Matlab you are using. If you are < R2014b then it will simply be a 'magic' double which you can query for the line properties.
Take a look at the output of
h = plot( x, y )
on the command line and you will see what it is. It is an object containing many useful properties of the line - e.g. colour, width, x data, y data

Connectez-vous pour commenter.

 Réponse acceptée

Adam
Adam le 2 Fév 2017
Modifié(e) : Adam le 2 Fév 2017

0 votes

figure; hAxes = gca;
x = [1 2 3];
y = [2 2.5 3.5];
plot( hAxes, x, y )
set( hAxes, 'YDir', 'reverse' ) % Or hAxes.YDir = 'reverse' from R2014b onwards

4 commentaires

Thanks!
This works fine for the above code, but when I applied it on the other code it doesn't work.
This one:
hAxes = gca;
% pixLoc(): a function that gets the locations
% of the desired pixels i.e. returns their columns and rows
[cp,rp] = pixLoc(Ic,6,4,38,348);
% a black image with the same size of the image Ic
imshow(imrotate(0*Ic,90))
hold on
% plotting points that I would like to flip
% (the blue points in the figure below)
plot(hAxes,cp,rp,'o');
hAxes.YDir = 'reverse';
Adam
Adam le 2 Fév 2017
Modifié(e) : Adam le 2 Fév 2017
What do you actually mean by flipping? What result do you expect from this? Do you want the max y value and min y value to be exchanged so that the curve is upside down? In that case you need to manipulate the data rather than the plot as e.g.
data = max( data ) - data + min( data );
Ezz El-din Abdullah
Ezz El-din Abdullah le 2 Fév 2017
I mean it's like considering the image a paper and I would like to flip it over upside down so that e.g. the point at y=20 will be at y=70 and so on.
Is it clear now?
Adam
Adam le 2 Fév 2017
Then you probably want the above maths or something similar. If you want 20 to become 70 then just substitute 70 and 20 in instead of max( data ) and min( data )

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Properties dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by