Basic Question on Imported Data Size

조회 수: 3 (최근 30일)
Ann
Ann 2014년 5월 6일
댓글: Tomas Jurena 2014년 5월 6일
Hi there! i'm a newbie in Matlab. I have 5x3000 size of imported data (5 row times 3000 data points). How can i change these data size to 1x15000 size (1 row times 15000 (4x3000+3000) data points? I know that I can use this command successfully: data=[data(1,:) data(2,:) data(3,:) data(4,:) data(5,:)]; but is there any short codes that can be used since I also have a big data size (30x3000). If I use the above command, I believe it will not be efficient in terms of command writing.
Annj

답변 (2개)

Chandrasekhar
Chandrasekhar 2014년 5월 6일
편집: Chandrasekhar 2014년 5월 6일
reshape(A,1,15000)
where A(3x5000) is the imported data
  댓글 수: 2
Ann
Ann 2014년 5월 6일
hi Akshata M. Thanks for your reply. I have tried use this command but it is not what I want. For example if I have these data: a =
1 4 7 10
2 5 8 11
3 6 9 12
then i applied b=reshape(a,1,12); the output will be:
b =
Columns 1 through 11
1 2 3 4 5 6 7 8 9 10 11
Column 12
12
However, the desired output that I wish to obtain should be arranged like this:
1 4 7 10 2 5 8 11 3 6 9
Please advice me on other suitable code. Thank you.
Tomas Jurena
Tomas Jurena 2014년 5월 6일
Just use transpose of the data matrix in reshape, i.e.
reshape(A',1,15000)
so in your example,
b = reshape(a',1,12)
produces the desired result
b =
1 4 7 10 2 5 8 11 3 6 9 12

댓글을 달려면 로그인하십시오.


Rowan
Rowan 2014년 5월 6일
the easiest way is to use matrix operations to rearrange the data. e.g. if you want to combine two 3 by 3 matrices, A and B, into a 6 by 3 matrix C (6 rows, 3 columns) you would have for example:
A = ones(3);B = ones(3)*2; (just to show the difference between matrices) then: C = [a;b], which would come out as: C = [1 1 1;1 1 1;1 1 1;2 2 2;2 2 2; 2 2 2]
using this method you can rearrange your imported data, like so: (we'll called the data imported D and the result after rearrangement matrix Dtest)
Dtest = [D(1,:) D(2,:) D(3,:) D(4,:) D(5,:)];
basically D(1,:) means all the data in the first row of matrix D so you just create a new matrix with all the rows of imported data in one line.
  댓글 수: 1
Ann
Ann 2014년 5월 6일
Hi Rowan! Thanks for your respond.
Correct me if i'm wrong, from your statement above, I understand that the Dtest code is the only way to create a new matrix with all the rows of imported data in one line which is also the same code as I mention in my first post.
My problem is that I have too many rows in my data (more than 30 rows), so is there any shortcut code that I can use in order to get all rows of imported data in one line? Thank you.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by