Problems plotting with linspace

2 visualizzazioni (ultimi 30 giorni)
Kurt Lee
Kurt Lee il 5 Giu 2017
Greetings. In particular, having several plots together using different vector lengths does not allow me to change the font, line colour, special character etc of the successive plots. Instead for the code below, it displays a strange rainbow colour line for the vertical plots y1 and y2. My question is, how to change the font, line colour, line width of plots y1 and y2?
x = linspace(-4, 3, 100);
a = ((5+x).^(0.5));
b = ((3/2).^((-7*x)/6));
ExpCurve = exp((x.^2).^0.5)+a.*b;
a1 = ((5-3.5).^(0.5));
b1 = ((3/2).^((-7*(-3.5))/6));
XL = exp(((-3.5).^2).^0.5)+a1.*b1;
y1 = linspace(0, XL, 40);
a2 = ((5+2.5).^(0.5));
b2 = ((3/2).^((-7*(2.5))/6));
XR = exp(((2.5).^2).^0.5)+a2.*b2;
y2 = linspace(0, XR, 40);
plot(x, ExpCurve, -3.5, y1, 2.5, y2, 'LineWidth', 2)
xlabel('x' , 'FontSize', 20)
ylabel('y' , 'FontSize', 20)

Risposte (1)

Walter Roberson
Walter Roberson il 5 Giu 2017
handles = plot(x, ExpCurve, -3.5, y1, 2.5, y2, 'LineWidth', 2);
set(handles(2), 'color', 'r', 'linewidth', 7)
set(handles(3), 'color', [.8 .1 .3], 'linewidth', 2)
  2 Commenti
Kurt Lee
Kurt Lee il 5 Giu 2017
The above response does not fix the problem. The code still generates the rainbow coloured vertical plots for y1 and y2.
Walter Roberson
Walter Roberson il 6 Giu 2017
You must be using an older MATLAB version; R2014b and later would not generate visible lines at all.
MATLAB has a rule for plotting that if X is a vector of length N, and Y is N x M then M lines will be plotted, as if by plot(X, Y(:,1), X, Y(:,2), X, Y(:,3) ... X, Y(:,N). Furthermore for convenience, if X is a vector of length N and Y is M x N (M ~= N) then Y will be internally transposed and then the one-line-per-column rule would be used.
You are using a scalar X, -3.5, with a vector y, y1. A scalar is 1 x 1, the row vector is 1 x M, so this fits the above situation with N = 1 -- 1 x N for X, N x M for Y, so M lines are being plotted, one for each column of Y, so one for each element of the vector y1. Switching to y1.' would not help because of the helpful automatic transpose.
Your corrected plot command would be
plot(x, ExpCurve, [-3.5 -3.5], [0 XL], [2.5 2.5], [0 XR], 'LineWidth', 2)

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by