Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
change the Ellipse angle

Subject: change the Ellipse angle

From: edward kabanyas

Date: 6 Oct, 2011 04:26:29

Message: 1 of 1

Hi All;

I want to add several Ellipse in my contour plot to high light several position of the data. I try make directly from plot editor of Matlab, but the angle is not changeable. And then I use the following code:

function [X Y] = calculateEllipse(x, y, a, b, angle, steps)
    %# This functions returns points to draw an ellipse
    %# @param x X coordinate
    %# @param y Y coordinate
    %# @param a Semimajor axis
    %# @param b Semiminor axis
    %# @param angle Angle of the ellipse (in degrees)

    error(nargchk(5, 6, nargin));
    if nargin<6, steps = 36; end

    beta = -angle * (pi / 180);
    sinbeta = sin(beta);
    cosbeta = cos(beta);

    alpha = linspace(0, 360, steps)' .* (pi / 180);
    sinalpha = sin(alpha);
    cosalpha = cos(alpha);

    X = x + (a * cosalpha * cosbeta - b * sinalpha * sinbeta);
    Y = y + (a * cosalpha * sinbeta + b * sinalpha * cosbeta);

    if nargout==1, X = [X Y]; end

p = calculateEllipse(0, 0, 20, 10, 50);
plot(p(:,1), p(:,2), '.-'), axis equal

The problem is the size not changeable by our hand. Do you have another way to change the angle of ellipse plotted by figure editor ?

Thanks for sharing..


Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us