Borrar filtros
Borrar filtros

How to transform a 2x5184 data set

1 visualización (últimos 30 días)
Dylan Girodat
Dylan Girodat el 16 de Dic. de 2018
Editada: Stephan el 16 de Dic. de 2018
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

Respuesta aceptada

Star Strider
Star Strider el 16 de Dic. de 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.

Más respuestas (2)

Stephan
Stephan el 16 de Dic. de 2018
Editada: Stephan el 16 de Dic. de 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

Mark Sherstan
Mark Sherstan el 16 de Dic. de 2018
Editada: Mark Sherstan el 16 de Dic. de 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

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by