plot a something in matlab

To plot a graph in Matlab, we can use the plot function. The general syntax is as follows:

main.m
plot(x, y)
11 chars
2 lines

x and y are the corresponding vectors of x and y values. For example, let's plot a sine wave from -pi to pi.

main.m
x = linspace(-pi, pi);
y =sin(x);
plot(x, y);
46 chars
4 lines

This will plot a sine wave graph in the current figure window.

We can also add labels and titles to the plot using the following functions:

  • xlabel('label'): adds x-axis label
  • ylabel('label'): adds y-axis label
  • title('title'): adds plot title

For example:

main.m
xlabel('Time (seconds)');
ylabel('Magnitude');
title('Sine wave');
67 chars
4 lines

This will add labels and title to the plot. We can customize the plot further by changing the line style, color, and adding markers. We can refer to the plot documentation for more information.

gistlibby LogSnag