i need to reshape rows that are in complicated manner!
1 回表示 (過去 30 日間)
古いコメントを表示
I have data in rows which is a bit complicated to arrange i need a code that will arrange in columns.
Example:
If A=
[1 3 5 7 9
2 4 6 8 10
1 3 5 7 9
2 4 6 8 10
1 3 5 7 9
2 4 6 8 10
1 3 5 7 9
2 4 6 8 10]
thats what data looks like. 1 and 2 rows contains data of same category so i want them to be arranged in a single column,same goes for the other three pairs in total i need 4 columns. but the reshaping command will put the 2nd column 1st value exactly after last value.
0 件のコメント
採用された回答
Roger Stafford
2016 年 12 月 19 日
The number of rows in A must be even.
n = size(A,2);
B = reshape(A.’,2*n,[]);
B = B(ceil((1:2*n)/2)+n*mod(0:2*n-1,2),:);
3 件のコメント
Roger Stafford
2016 年 12 月 19 日
In the quantity
p = ceil((1:2*n)/2)+n*mod(0:2*n-1,2)
what we need is
p = [1,1+n,2,2+n,3,3+n,...]
in order to do the proper rearrangement. The first term will be:
ceil((1:2*n)/2) = [1,1,2,2,3,3,...]
and the second term will give:
n*mod(0:2*n-1,2) = [0,n,0,n,...]
Adding these together gives the p that we require.
その他の回答 (2 件)
John D'Errico
2016 年 12 月 18 日
Easy.
A = reshape(A',10,4);
A =
1 1 1 1
3 3 3 3
5 5 5 5
7 7 7 7
9 9 9 9
2 2 2 2
4 4 4 4
6 6 6 6
8 8 8 8
10 10 10 10
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!