필터 지우기
필터 지우기

How to transform a 2x5184 data set

조회 수: 1 (최근 30일)
Dylan Girodat
Dylan Girodat 2018년 12월 16일
편집: Stephan 2018년 12월 16일
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