Now this is sort of a basic thing about Matlab, but until recently I hadn't really though of it.
Concatenation.
Everyone needs to do it.
What is concatenation? Simply, it's when you stack two vectors on top of one another.
For example, if you have
2
3
4
and
5
6
7
the concatenated vector is
2
3
4
5
6
7
You might use this a lot in data processessing, etc.
To put vectors together vertically it's pretty easy, you just use the format
new vector = ([x ; y])
The semi colon indicates put them together vertically.
To put vectors next to one another horizontally, you just say;
new vector = [ x y]
No semicolon indicates they should be next to one another. Note that this will ONLY work if they are the same length. One of my favorite uses for horizontal "joins" (if you will) is actually to use this property to "test" if my vectors are the same length. If i have a list of indices to line up, this serves nicely.
You can also do more complex things, such as joining rows in an array, like this
new array = ([oldarray (1:3, :); oldarray (5:8,:) ; oldarray (10:245,:)])
Okay, so not the most exciting post today, but trust me--- if you don't ever see this written by someone else, I think it's hard to figure out!
No comments:
Post a Comment