How to Insert a Value in an Array in MATLAB

Written by joe friedman
  • Share
  • Tweet
  • Share
  • Email

MATLAB is an incredibly versatile mathematics and engineering tool, capable of advanced calculations and engineering simulations. A simple function of MATLAB is to store a list of numbers in what it calls an array. You can define the array values automatically through a function or assign them one-by-one directly. MATLAB stores matrices internally as arrays, appended row after row. The program refers to each spot in the array as an "element" and refers to the m-th element in array "A" as "A(m)."

Skill level:
Moderately Easy

Other People Are Reading

Instructions

  1. 1

    Define an array, using any method. For example, "A = [1 2 3 4]" creates an array of four elements with the numbers 1, 2, 3 and 4.

  2. 2

    Insert a value into an array by typing "A(m) = value" where "A" is the matrix name, "m" is which element, sequentially, you want to define and "value" is the number you want the "m-th" element in "A" to have.

  3. 3

    Note that following these steps and using step one's matrix "A," "A(2) = 5" causes MATLAB to output the following:

    A =

     1     5     3     4
    

    Notice that MATLAB changed the 2nd element in "A" to a 5.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.