Rearrange a matrix by the values of the first column
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Day Hong Kim
el 17 de Dic. de 2020
Comentada: Day Hong Kim
el 18 de Dic. de 2020
Hello all, I would like to rearrange the matrix according to the values in the first column. the first column represents station number and the second column represents value acquired from the corresponding station ( I attached the file). I have 9 stations, so I want a n x 9 matrix where n is the values from each station. It would be like
0 0 0 0
10 10 10 10
20 20 20 20
30 30 30 30
50 50 50 50
75 75 75 75
125 125
150 150
2 comentarios
KALYAN ACHARJYA
el 17 de Dic. de 2020
If you want help, you need to make it easy to undestand. Please elaborate the question with small sample example
Respuesta aceptada
Matt J
el 17 de Dic. de 2020
load(websave('question.mat','https://www.mathworks.com/matlabcentral/answers/uploaded_files/464105/question.mat'));
G=findgroups(stationdepth(:,1));
n=max(histcounts(G,1:max(G)+1));
out=nan(n,9);
for i=1:9
bool=(G==i);
out(1:nnz(bool),i)=stationdepth(bool,2);
end
out
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices 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!