2 Plots Matlab

2 Plots Matlab Average ratng: 3,9/5 1901 reviews

Objective: To study graphics, i.e., 2-D plots, printing labels, grid and axis box, text in plot, bar, and pie chart.

  • Basic two dimensional plots in Matlab. Subplots and multiplots. Saving figure in.pdf,.tif,.png in any desired format.
  • Plot Additional Data Against Each Side. Add two more lines to the left side using the hold on command. Add an errorbar to the right side. The new plots use the same color as the corresponding y-axis and cycle through the line style order. The hold on command affects both the left and right sides.

Create two comet plots in a tiled chart layout by specifying the target axes for each plot. Create two data sets, x1 and y1 and x2 and y2 as vectors of trigonometric functions with input values from 0 to 4 π. Specify the body length scale factor p as 0.25 so that the body length is 0.25.length(y).

Example

Output:

Multiple plots:

Examples

Output:

Line color, Line style, Marker style, and legends:

  • Line color:
  • Marker style:
Matlab
  • Line style:

TITLE:

Title ('title_string', 'Font Name', Helvetica','Font Size',20.'color','green','Font Weight','light/bold/normal','Font Angle','Normal/italic');

AXES:

Axes('Position',[left, bottom,width,height])

E.g.: To create axes at (0.2,0.2), size half of the figure window.

axes ('Position', [.2 .2 .5 .5]);

TEXT:

To add a text string to a specified location in the plot area.

text(r,c,'string');

GTEXT: need not to specify text location.

gtext('string');

where we click, the text will be displayed there.

LEGEND:

Position of legend:

Example

2 plots matlab worksheet

Output:

Statistical plots:

pie(x):

Plots

Example

Output:

To pull out 3rd slide:

Example

Output:

To pull text labels:

Example

Output:

Bar graphs:

2 Plots Matlab

bar(x): It plots the bar. Plot the values of x against the time index.

bar(t,x): if we want to give t by ourselves.

How To Plot Separate Graphs In Matlab

Example

Output:

Matlab 2 Plots On 1 Figure

bar(x,'stacked'):

Output:

Print command:

print<option><filename>

options:

  • -deps: It creates a monochrome encapsulated postscript image.
  • -depsc: It creates a colored encapsulated postscript image.
  • -djpeg: Its joint photography expert group.
  • -dpng: Its portable network graphics.

E.g.: print -djpeg myimg.jpeg


This example shows how to create a variety of 2-D plots in MATLAB®.

Line Plots

The plot function creates simple line plots of x and y values.

Line plots can display multiple sets of x and y data.

Bar Plots

The bar function creates vertical bar charts. The barh function creates horizontal bar charts.

Stairstep Plots

The stairs function creates a stairstep plot. It can create a stairstep plot of Y values only or a stairstep plot of x and y values.

Errorbar Plots

The errorbar function draws a line plot of x and y values and superimposes a vertical error bar on each observation. To specify the size of the error bar, pass an additional input argument to the errorbar function.

Polar Plots

The polarplot function draws a polar plot of the angle values in theta (in radians) versus the radius values in rho.

Create

Stem Plots

The stem function draws a marker for each x and y value with a vertical line connected to a common baseline.

Scatter Plots

The scatter function draws a scatter plot of x and y values.

Use optional arguments to the scatter function to specify the marker size and color. Use the colorbar function to show the color scale on the current axes.

Related Topics

Comments are closed.