How to Save Variables in an Array in MATLAB

Save

Matrix Laboratory (MATLAB) is a matrix-based, technical computing language. The program allows you to store various types of data in matrixes. These matrixes can be one-dimensional arrays or multi-dimensional variables. Once you have created several different variables in one work space, you may wish to store all of those variables in one variable. Fortunately, MATLAB has a solution for this: a cell array. Cell arrays can be created with the "cell" function.

Things You'll Need

  • MATLAB R2007a (or later version)
  • Open MATLAB.

  • Type the following in the command window:

    "a = cell(N)"

    where "a" is the name of the array. "N" should be the number of variables you want to save in the array.

  • Save a variable in the array by typing the following in the command window:

    "a{1} = Variable1"

    where "Variable1" is the name of the first variable you want to save in the array.

  • Save another variable in the array by typing the following in the command window:

    "a{2} = Variable2"

    where "Variable2" is the name of the second variable you want to save in the array.

  • Repeat the above operation until you have saved "N" variables in the array, that is, you have filled each of the array's "N" slots.

Tips & Warnings

  • Make sure to use curly brackets ({) instead of parentheses when saving variables to your cell array. Otherwise, your commands will produce an error.

Related Searches

References

Promoted By Zergnet

Comments

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!