declare

Matlab Arrays 01 - Creating a 1D Array



Sharing buttons:

in this video we're going to learn how

to create a 1 dimensional array in

MATLAB so suppose we want to enter the

depth at breast height and trees per

acre data into MATLAB so we can create a

one-dimensional array with the depth at

breast height data and then we can

create another one dimensional array

with the trees per acre data so let's

start with the depth of breast height

data we want to create a 1 dimensional

array and we're gonna call it DB h to

stand for depth at breast height so

we're going to say that DB H is equal to

and then we're going to use a left

square bracket sometimes also called an

open square bracket and then we'll start

to list the data points separated by

spaces so we'll have 22.9 that's the

first data point and then a space will

have 30 point-0 and the space 30.3 and

space 27.8 space

24 point one twenty eight point two

twenty six point four twelve point eight

thirty nine point seven amp'd 38.0 all

right so each data point is separated

with a space and at the end I put a

right square bracket or a closed square

bracket and when I press ENTER I see the

data here now notice that the command

window is not wide enough to list all of

the data points out in one row so first

it shows me columns one through eight

and then it shows me columns nine and

ten so it shows me the first eight data

points and then it shows me the last two

on the next line now if we look over in

the workspace here I have my variable

name DBH but look at the value the value

is now this list of data points and

let's see if I scoot this out just a

little bit more we can also see the

minimum data point value and the maximum

data point value and scoot this back for

a second if we double-click on DBH it

opens a variable editor which I'm going

to scoot over to share it with a command

window so the variable editor looks like

a spreadsheet but the very when we're

inside the variable editor we can edit

the values that we have entered into our

rhyme so let's say I had messed up on

entering in one of the values and 30.3

should not be 30.3 but it should be

thirty point one well I could double

click on the entry I'll send a lot of

zeros apparent I can delete what is

incorrect and put in a one and press

Enter and now I've changed the value so

let me go back change it to what it

should be back to thirty point three all

right so I'm going to click back over

here to the command window so the next

thing that we're going to do is we're

going to create an array for the trees

per acre the number of trees per acre so

I'm gonna call that TPA put an equal

sign and some square brackets now I'm

feeling kind of lazy and I don't want to

type in all of the data so instead I'm

going to copy and paste so it just so

happens that I have the PDF of the

boudin Linhart and gross math for life

science textbook open which is where

this data comes from so I'm just going

to copy this row of data so I'm going to

get my text select tool I'm gonna

highlight the data that I want right

click copy or control C to copy then

I'll come back over here and

if I right-click I can paste it in or I

can press ctrl-v alright so notice this

actually inserts a couple of spaces

between each data point but that's okay

as long as there's at least one space

between each data point it will work out

okay so now I'm gonna press ENTER and

once again we see that the first eight

columns of data are displayed first and

then columns 9 and 10 of the data so if

we look over at the workspace again now

I see that I have another variable and

again I can open up this variable and

look at it in the variable editor and I

can change any values that I need to if

I entered in something wrong but we

actually don't have to go through the

variable editor if we want to make a

change there's another way so if I come

back over to the command window let's

say I messed up entering something in

the trees per acre data what I can do

instead is I can scroll up so I'm going

to press the up arrow key and that

brings up the very last command is that

I entered in and then I can either use

the cursor or use the mouse to move the

cursor and I can highlight a value and

change it or since the cursor is at the

end I can use the left and right arrow

keys to move the cursor around so let's

change the 18 point 0 to 18 point 1 so I

just deleted the 0 put in a 1 and then

I'll move the cursor down to the end and

I'll press ENTER and now I see that I've

changed that data point to 18 point 1

all right so to recap you should now

know how to enter a 1 dimensional array

of data into MATLAB how to view that

data in the variable head etre window

and how to edit any particular value

within an array either through the

variable editor window or through the

command window