# Plot a vector with a given angle against the y-axis

8 views (last 30 days)

Show older comments

##### 0 Comments

### Answers (2)

Paul
on 20 Apr 2024

Edited: Paul
on 20 Apr 2024

Something like this? Note that the line won't won't resize if the axes are resized. If you want something like that, you might be able to use a combination of xline and hgtransform, but I didn't try it.

rng(100);

figure;scatter(randn(100,1),randn(100,1))

theta = 30;

yl = ylim;

line([yl(1)*tand(30) yl(2)*tand(30)],[yl(1) yl(2)])

##### 0 Comments

Star Strider
on 20 Apr 2024

Edited: Star Strider
on 20 Apr 2024

Another approach —

thetad = 280; % Desired Angle (Guessing Value)

x = randn(100,1)*2;

y = randn(100,1);

% thetad = 360*rand

arcang = linspace(mod(thetad, 180), 90, 25);

arc = @(yv) [(max(yv)/2)*cosd(arcang); (max(yv)/2)*sind(arcang)];

figure

scatter(x, y, 'x')

hold on

plot(xlim*cosd(thetad), xlim*sind(thetad), '-b', 'LineWidth',2)

arcs = arc(ylim);

plot(arcs(1,:), arcs(2,:), '-b', 'LineWidth',2)

hold off

axis('equal')

title('Normal Ticks, Tick Labels, & Axes, With Solid Lines For Axes')

Ax = gca;

Ax.XAxisLocation = 'origin';

Ax.YAxisLocation = 'origin';

text(median(arcs(1,:)), median(arcs(2,:)), '\theta', 'Horiz','center', 'Vert','bottom', 'Color','b', 'FontSize',16)%, 'FontWeight','bold')

% get(Ax)

figure

scatter(x, y, 'x')

hold on

plot(xlim*cosd(thetad), xlim*sind(thetad), '-b', 'LineWidth',2)

arcs = arc(ylim);

plot(arcs(1,:), arcs(2,:), '-b', 'LineWidth',2)

hold off

axis('equal')

xline(0, '--k', 'LineWidth',2) % Draw Y-Axis

yline(0, '--k', 'LineWidth',2) % Draw X-Axis

title('Invisible Itcks, Tick Labels, & Axes, With Dashed Lines For Axes')

Ax = gca;

Ax.XAxis.Visible = 0;

Ax.YAxis.Visible = 0;

text(median(arcs(1,:)), median(arcs(2,:)), '\theta', 'Horiz','center', 'Vert','bottom', 'Color','b', 'FontSize',16)%, 'FontWeight','bold')

EDIT — (20 Apr 2024 at 19:14)

Made ‘arcang’ more robust.

.

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!