4.8.1: Plotting Vectors Additional Material

Matlab and Octave Programming for STEM Applications · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC-SA 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    4.8.1: Plotting Vectors Additional Material

      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')

      Exercise \(\PageIndex{1}\) Voltage_Vector

      (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.

      .


      This page titled 4.8.1: Plotting Vectors Additional Material was last modified on Tue, 06 Feb 2024 14:38:52 GMT and is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Carey Smith.