semilogx
Define
x
as a vector of logarithmically spaced values from0.1
to100
, and definey
as a copy ofx
. Create a linear-log plot ofx
andy
, and call thegrid
function 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
f
as a vector containing the frequencies from 10 Hz to 100,000 Hz. Definegain
as 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
yticks
function to reposition the y-axis tick values at whole-number increments along the y-axis. Then create x- and y-axis labels by calling thexlabel
andylabel
functions.
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 thelegend
function.
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,
semilogx
plots those coordinates against the values1:length(y)
. For example, definey
as a vector of 5 values between0
and 40
. Create a linear-log plot of y.
y = [0 10 20 30 40]; semilogx(y) grid on fig2plotly()
If you specify
y
as a matrix, the columns of y are plotted against the values1:size(y,1)
. For example, definey
as a 5-by-3 matrix and pass it to thesemilogx
function. The resulting plot contains 3 lines, each of which has x-coordinates that range from1
to5
.
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 thenexttile
function to create an axes object and return it asax1
. Then display a linear-log plot by passingax1
to thesemilogx
function.
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
NaN
values wherever there are discontinuities in your data. Thesemilogx
function displays gaps at those locations.Create a pair of x- and y-coordinate vectors. Replace the fortieth y-coordinate with a
NaN
value. Then create a linear-log plot ofx
andy
.
x = logspace(-1,2); y = x; y(40) = NaN; semilogx(x,y) fig2plotly()