re arrange shape matrix according to the position of a index value in array.

2 views (last 30 days)
Dear friends, many thanks for helping me, it was succesfull.
I would like to help me in this task, having the next file as example, I will try to explain with only a reduced number of values of the file.
Below is what I have to start, I would need something what is able to do what is shown in "desired output"
imput:
306,000 305,952 304,683 302,265 300,219
306,000 306,008 304,977 302,450 299,846
306,000 305,962 304,840 302,413 299,812
306,000 306,051 305,051 302,396 299,877
306,000 306,003 304,891 302,163 300,017
306,000 306,004 305,002 301,997 300,186
406,000 406,016 404,943 402,467 400,224
406,000 406,009 404,961 402,483 400,361
406,000 406,014 404,852 402,547 400,287
406,000 406,043 404,990 402,520 400,372
406,000 406,048 405,105 402,425 400,817
406,000 406,034 404,928 402,425 400,623
506,000 506,038 505,182 502,518 500,878
506,000 506,003 505,208 502,728 500,684
506,000 505,971 505,110 502,841 501,118
506,000 505,979 505,083 502,644 500,922
506,000 505,985 505,065 502,942 500,955
506,000 506,062 505,067 502,818 501,280
output:
(first 3 rows of all groups of same index)
306,000 305,952 304,683 302,265 300,219
406,000 406,016 404,943 402,467 400,224
506,000 506,003 505,208 502,728 500,684
(second 3 rows of all groups of same index)
306,000 306,008 304,977 302,450 299,846
406,000 406,009 404,961 402,483 400,361
506,000 506,003 505,208 502,728 500,684
(third 3 rows of all groups of same index
306,000 305,962 304,840 302,413 299,812
406,000 406,014 404,852 402,547 400,287
506,000 505,971 505,110 502,841 501,118
fourth 3 rows of all groups of same index
306,000 306,051 305,051 302,396 299,877
406,000 406,043 404,990 402,520 400,372
506,000 505,979 505,083 502,644 500,922
fifth...
306,000 306,003 304,891 302,163 300,017
406,000 406,048 405,105 402,425 400,817
506,000 505,985 505,065 502,942 500,955
sitxh...
306,000 306,004 305,002 301,997 300,186
406,000 406,034 404,928 402,425 400,623
506,000 506,062 505,067 502,818 501,280
The desired output would be if, for instance, in the original file I have 234 indexed in groups of 6 rows, I would like to obtain at the end matrix of 39x5 , and the number of matrix is the length, or the amount of rows that I have per group.
So, how could I do it?, save these results also would be needed.
I hope to have been clear. And, anyway, many thanks for your help. It was very useful for me, and I am doing little steps to learn how to program.
Best Regards,
Miguel

Answers (1)

Andrei Bobrov
Andrei Bobrov on 8 Sep 2013
Edited: Andrei Bobrov on 8 Sep 2013
x = dlmread('x.txt');
out = permute(reshape(x,[],numel(unique(x(:,1))),size(x,2)),[2 3 1]);
ADD
s = size(x);
n = s(1)/numel(unique(x(:,1)));
out = reshape(permute(reshape(x,n,[],s(2)),[2 1 3]),s);

Community Treasure Hunt

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

Start Hunting!