semilogxDefine
xas a vector of logarithmically spaced values from0.1to100, and defineyas a copy ofx. Create a linear-log plot ofxandy, and call thegridfunction to show the grid lines.
x = logspace(-1,2); y = x; semilogx(x,y) grid on fig2plotly()
Create a vector of logarithmically spaced x-coordinates and two vectors of y-coordinates. Plot two lines by passing comma-separated x-y pairs to
semilogx.
x = logspace(-1,2); y1 = x; y2 = -x; semilogx(x,y1,x,y2) grid on fig2plotly()
Define
fas a vector containing the frequencies from 10 Hz to 100,000 Hz. Definegainas a vector of power gain values in decibels. Then plot the gain values against frequency.
f = logspace(1,5,100); v = linspace(-50,50,100); gain = (1-exp(5*(2.5*v.^2)./7500))/14; semilogx(f,gain) grid on fig2plotly()
Call the
yticksfunction to reposition the y-axis tick values at whole-number increments along the y-axis. Then create x- and y-axis labels by calling thexlabelandylabelfunctions.
yticks([-5 -4 -3 -2 -1 0])
xlabel ('Freqency (Hz)')
ylabel('Power Gain (dB)')
Create a set of x- and y-coordinates and display them in a linear-log plot. Specify the line style as
'o'to display circular markers without connecting lines. Specify the marker fill color as the RGB triplet[0 0.447 0.741], which corresponds to a dark shade of blue.
x = logspace(-1,2,15); y = 12 + x; semilogx(x,y,'o','MarkerFaceColor',[0 0.447 0.741]) grid on fig2plotly()
Create a vector of logarithmically spaced x-coordinates and two vectors of y-coordinates. Then plot two lines by passing comma-separated x-y pairs to
semilogx. Display a legend by calling thelegendfunction.
x = logspace(1,4,100);
v = linspace(-50,50,100);
y1 = 100*exp(-1*((v+5).^2)./200);
y2 = 100*exp(-1*(v.^2)./200);
semilogx(x,y1,x,y2,'--')
legend('Measured','Estimated')
grid on
fig2plotly()
When you specify only one coordinate vector,
semilogxplots those coordinates against the values1:length(y). For example, defineyas a vector of 5 values between0and 40. Create a linear-log plot of y.
y = [0 10 20 30 40]; semilogx(y) grid on fig2plotly()
If you specify
yas a matrix, the columns of y are plotted against the values1:size(y,1). For example, defineyas a 5-by-3 matrix and pass it to thesemilogxfunction. The resulting plot contains 3 lines, each of which has x-coordinates that range from1to5.
y = [ 0 10 20
10 20 30
20 30 40
30 40 50
40 50 60];
semilogx(y)
grid on
fig2plotly()
Create a tiled chart layout in the
'flow'tile arrangement, so that the axes fill the available space in the layout. Next, call thenexttilefunction to create an axes object and return it asax1. Then display a linear-log plot by passingax1to thesemilogxfunction.
tiledlayout('flow')
ax1 = nexttile;
x = logspace(-1,2);
y1 = 1./x;
semilogx(ax1,x,y1)
fig2plotly()
Repeat the process to create a second linear-log plot.
ax2 = nexttile; y2 = x; semilogx(ax2,x,y2) fig2plotly()
Create a linear-log plot containing two lines, and return the line objects in the variable
slg.
x = logspace(-1,2); y1 = x; y2 = -x; slg = semilogx(x,y1,x,y2); fig2plotly()
Change the width of the first line to
3, and change the color of the second line to purple.
slg(1).LineWidth = 3; slg(2).Color = [0.4 0 1]; fig2plotly()
Insert
NaNvalues wherever there are discontinuities in your data. Thesemilogxfunction displays gaps at those locations.Create a pair of x- and y-coordinate vectors. Replace the fortieth y-coordinate with a
NaNvalue. Then create a linear-log plot ofxandy.
x = logspace(-1,2); y = x; y(40) = NaN; semilogx(x,y) fig2plotly()