how do i plot a straight line and also change then range of the x axis and y axis ?

12 visualizzazioni (ultimi 30 giorni)
Vonew=45;
Vonew2=15
Vonew2 = 15
vin=30;
y=Vonew; %i get my Voutnew=45
x=Vonew2;
plot( Vonew,y, 'o', 'LineWidth', 2);
hold on
plot( Vonew2,x, 'o', 'LineWidth', 2);
xlabel('vin', 'FontSize', 20);
ylabel('vo', 'FontSize', 20);
title('vo vs vin', 'FontSize', 20);

Risposte (2)

Rik
Rik il 16 Feb 2022
I suspect you want something like xline or yline:
Vonew=45;
Vonew2=15
Vonew2 = 15
vin=30;
y=Vonew; %i get my Voutnew=45
x=Vonew2;
plot( Vonew,y, 'o', 'LineWidth', 2);
hold on
plot( Vonew2,x, 'o', 'LineWidth', 2);
xlabel('vin', 'FontSize', 20);
ylabel('vo', 'FontSize', 20);
title('vo vs vin', 'FontSize', 20);
xline(30),yline(20)
axis([14 46 14 46])

Mathieu NOE
Mathieu NOE il 16 Feb 2022
hello Grace
maybe this ?
I added a line between the two points you defined and using xlim and ylim you can change the visual appearance of your graph
Vonew=45;
Vonew2=15;
vin=30;
y=Vonew; %i get my Voutnew=45
x=Vonew2;
% line
n = 100; % dots
x_line = linspace(Vonew,Vonew2,n); % put here the first and last point x coordinates
y_line = linspace(y,x,n); % put here the first and last point y coordinates
plot( Vonew,y, 'o', 'LineWidth', 2);
hold on
plot( Vonew2,x, 'o', 'LineWidth', 2);
plot( x_line,y_line, 'k--', 'LineWidth', 2); % line
% set x and y display limits
xlim([0 1.4*max(x_line)]);
ylim([0 1.4*max(y_line)]);
xlabel('vin', 'FontSize', 20);
ylabel('vo', 'FontSize', 20);
title('vo vs vin', 'FontSize', 20);
hold off
  2 Commenti
Rik
Rik il 16 Feb 2022
You don't even need the linspace:
Vonew=45;
Vonew2=15;
vin=30;
y=Vonew; %i get my Voutnew=45
x=Vonew2;
% line
n = 100; % dots
x_line = [Vonew,Vonew2]; % put here the first and last point x coordinates
y_line = [y,x]; % put here the first and last point y coordinates
plot( Vonew,y, 'o', 'LineWidth', 2);
hold on
plot( Vonew2,x, 'o', 'LineWidth', 2);
plot( x_line,y_line, 'k--', 'LineWidth', 2); % line
% set x and y display limits
xlim([0 1.4*max(x_line)]);
ylim([0 1.4*max(y_line)]);
xlabel('vin', 'FontSize', 20);
ylabel('vo', 'FontSize', 20);
title('vo vs vin', 'FontSize', 20);
hold off
Mathieu NOE
Mathieu NOE il 16 Feb 2022
hello @Rik
you're right - it's even better this way
I'm sometimes still coding like I was doing 20 years ago

Accedi per commentare.

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by