How to transform a 2x5184 data set
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Star Strider
on 16 Dec 2018
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.
0 Comments
More Answers (2)
Stephan
on 16 Dec 2018
Edited: Stephan
on 16 Dec 2018
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
0 Comments
Mark Sherstan
on 16 Dec 2018
Edited: Mark Sherstan
on 16 Dec 2018
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
0 Comments
See Also
Categories
Find more on Data Preprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!