How to transform a 2x5184 data set

1 次查看(过去 30 天)
Hi,
I am trying to transform my 2x5184 data set into a 72x72 data set.
I would like the data to read as
2.0000 28.2000 28.2000 25.8000 24.7000 23.5000 24.7000 28.2000 ....
2.0694 28.2000 28.2000 22.3000 21.1000 20.0000 21.1000 20.0000 ....
If you see below in the data set I have now the first 72 iterations of column 1 are the same value and then the next 72 are the same. I would like to put all the values in the second column that correspond to the same value in column 1 into a single row. Is there an easy way to do this?
the data set currently looks like this
2.0000 28.2000
2.0000 28.2000
2.0000 25.8000
2.0000 24.7000
2.0000 23.5000
2.0000 24.7000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 22.3000
2.0694 21.1000
2.0694 20.0000
2.0694 21.1000
2.0694 20.0000
2.0694 22.3000
2.0694 25.8000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000
2.0694 28.2000

采纳的回答

Star Strider
Star Strider 2018-12-16
Try this:
D = [2.0000 28.2000
2.0000 28.2000
2.0000 25.8000
2.0000 24.7000
2.0000 23.5000
2.0000 24.7000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
. . . ];
[Du,~,idx] = unique(D(:,1));
rv = accumarray(idx, D(:,2), [], @(x){x});
Out = [Du, reshape(cell2mat(rv'), [], numel(Du))']
Out =
Columns 1 through 11
2.0000 28.2000 28.2000 25.8000 24.7000 23.5000 24.7000 28.2000 28.2000 28.2000 28.2000
2.0694 28.2000 28.2000 22.3000 21.1000 20.0000 21.1000 20.0000 22.3000 25.8000 28.2000
...and so for the rest.

更多回答(2 个)

Stephan
Stephan 2018-12-16
编辑:Stephan 2018-12-16
Hi,
here is a small example - change k to 72 to adapt for your case:
k = 3; % in your case 72
A = [2 28.2; 2 28.2; 2 28.2; 2.0694 28.1; 2.0694 28.1; 2.0694 28.1]
Result = [unique(A(:,1)) reshape(A(:,2),k,[])']
Results are:
A =
2.0000 28.2000
2.0000 28.2000
2.0000 28.2000
2.0694 28.1000
2.0694 28.1000
2.0694 28.1000
Result =
2.0000 28.2000 28.2000 28.2000
2.0694 28.1000 28.1000 28.1000
I think this is what you want.
Best regards
Stephan

Mark Sherstan
Mark Sherstan 2018-12-16
编辑:Mark Sherstan 2018-12-16
Another possible solution:
B = zeros(72);
B(1,:) = A(1:72,2)';
idxLow = 72;
idxHigh = 143;
for ii = 2:72
B(ii,:) = A(idxLow:idxHigh,2)';
idxLow = idxLow + 71;
idxHigh = idxHigh + 71;
end

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by