4.8.1: Plotting Vectors Additional Material
- Page ID
- 87663
Watch this video on making an x-y plot with vectors. It also shows how to plot 2 curves on 1 figure with "hold on".
MATLAB Function Plotting Basics, Robert Talbert
Important note:
When a function has more than 1 input, you must put commas between the inputs.
Even though you can leave-out commas when specifying a vector such as x = [1 2 5 8], this does not work for functions. The commas between the inputs are required.
Examples:
plot(x, y), not plot(x y)
plot(x, y, '*'), not plot(x y '*')
.
Additional MATLAB functions for labeling plots:
title() puts a title on a plot. The argument of title is a character string.
Examples:
title('sin(x) vs. t')
xlabel() and ylabel() put labels on the x and y axes of a plot.
Examples:
xlabel('Time (s)')
ylabel('Distance')
(1 pt) Create a Matlab script: voltage_vector_YourName.m
(1 pt) Clear any variables; close any figures; eliminate white space; clear the console
clear all; close all; format compact; clc;
%% V = IR
(2 pts) Create a vector I (current) from 0 to 15 amps in steps of 3 amps
(2 pts) Create a vector R (resistance) from 100 to 600 Ohms in steps of 100 Ohms
(2 pts) Compute the corresponding vector of voltages by multiplying I time R element-wise with this code
V = I.*R % (volts)
%% Plot
% (1 pt) Open a figure window
% (1 pt) Plot V (y-axis) vs. I (x-axis) with this code:
plot(I, V, '-o')
title('Voltage vs. Current')
% (1 pt) Label the x-axis with this code:
xlabel('I (amps)')
% (1 pt) Label the y-axis with this code:
ylabel('V (volts)')
- Answer
-
The solution is not given here.
.