Skip to content

Data From Many Columns Into One Using MATLAB (Simple Code)

September 11, 2012

Sometimes you want to arrange data from many columns into one using MATLAB. Such a task should be easy to perform. However I had some difficulties and couldn’t find help online right away, so I descided to share a simple solution.

Start with (or any data):

data1 =

8 1 6
3 5 7
4 9 2

To achieve:

data2 =

8
3
4
1
5
9
6
7
2

This program will do the trick:

data1=magic(3) %or any data
a=[]; %storage vector
for i=1:length(data1(1,:))
b=data1(:,i);
a=[a b’];
end
data2=a’

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: