Categories

# Matlab loglog()

In MATLAB, loglog() function is a 2D plot creation function that generates a plot with a logarithmic scale (base 10). It plots data sets of both ‘x’ and ‘y’ axes in the logarithmic scale. It is basically useful to generate plot either for very large values or very small positive values. The plot is generated from loglog() function by setting the properties of the axes, XScale and YScale to ‘log’.

This function also allows us to generate a logarithmic plot for complex numbers setting the real value of the input as x-axis coordinates and imaginary value of the input as y-axis coordinates.

## Syntax of Matlab loglog()

Syntax of Matlab loglog() are given below:

## Syntax:

Various syntaxes are supported by the MATLAB function loglog() depending on the of plot to be generated.

## Examples of Matlab loglog()

Following are the examples of Matlab loglog().

## Example 1:

``````xdata = logspace(-2,3);
ydata = 5.^xdata+2;
loglog(xdata,ydata)
grid on``````

## Output:

The loglog() enables the user to create multiple plots sharing a common x-y plane, calling a single line command. This is possible with the implementation of the syntaxloglog(X1,Y1,……,Xn,Yn,___).

## Example 2:

``````xdata = logspace(-3,5);
ydata1 = 10.^xdata;
ydata2 = 1./10.^xdata;
loglog(xdata, ydata1,xdata,ydata2)
grid on``````

## Output:

Here the logarithmic plot for the inputs ydata1 and ydata2 are created with the common x-coordinates from xdata.

The syntax also supports the customization of plots using the input argument as LineSpec value.

## Example 3:

``````x1 = logspace(-1,2,10000);
x2 = logspace(-3,5,20000);
y1 = 6 + 3*cos(x1/4);
y2 = 6 - 3*cos(x2/4);
loglog(x1,y1,x2,y2,'--')
legend('Signal 1','Signal 2')``````

## Output:

The function extends its feature to provide flexibility on the customization of the plot even after it is generated. This feature can be used by using the line object to store the plot generated from the loglog() function.

## Example 4:

``````xdata = logspace(-1,2);
ydata1 = 10.^xdata;
ydata2 = 1./10.^xdata;
lg = loglog(xdata,ydata1,xdata,ydata2);
lg(1).LineWidth = 3;
lg(2).Color = [0.5 1 1];``````

## Input Arguments:

The syntaxes are developed based on the input arguments supported by the function definition. Different parameters that can be used as input parameters are described in the below table:

## Example 5:

``````tiledlayout('flow')
axdata1 = nexttile;
x = logspace(-1,2);
y1 = 10.^x;
loglog(axdata1,x,y1)
axdata2 = nexttile;
y2 = 1./10.^x;
loglog(axdata2,x,y2)``````

## Attributes:

The function supports customization of the plot generated through it, by means of some of the predefined attributes. The display of the plot can be altered by altering the values of the attributes following the format of the name-value pair argument.

## Example 6:

``````xdata = logspace(-2,1,50);
ydata = 15.^xdata;
loglog(xdata,ydata,'s','MarkerFaceColor',[0 0.447 0.741])
grid on``````