# MATLAB Programming/Plot

## IntroductionEdit

The *plot* command plots 2D data linearly to the current axis on the current figure.

## UsageEdit

Here's how a plot can be created.

```
>> h = figure; % Create new figure and save the handle to h
>> x = [0:0.001:10]; % Create x vector
>> y = sin(x);
>> plot(x, y) % Plot
>> title('Sine wave from 0 to 10') % Set the title of the current axis
>> ylabel('sin(x)') % Set the label for the y-axis
>> xlabel('x') %set the label for the x-axis
% xlabel('alpha') - - > alpha
% xalbel('\alpha') - -> symbolic alpha
>> grid on % Turn on the grid
```

Graphs can also be created and saved using the command line interface. For example, the following code will create a graph comparing the speedup of two algorithms. The graph created is shown below.

```
>> x = [1 2 4 8];
>> y = [1 2 1.95 3.79];
>> z = [1 1.73 2.02 3.84];
>> h = plot(x,y,'--');
>> hold on; % Plot next graph on same figure
>> plot(x,z);
>> hold off;
>> xlabel('Number of processors');
>> ylabel('Speedup');
>> saveas(h,'graph.eps',eps);
```