How do i sort table rows based on other table rows ?
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ahmed obaid
el 8 de Jun. de 2017
Respondida: Andrei Bobrov
el 8 de Jun. de 2017
Dear experiences..
i have two tables.. A and B..
where table A involves ( id, num, var1 , var2).., and table B involves (num, var1.....varn).. i need to sort either table A rows based on table B num order or vise versa... how do i perform this task ?
thanks
0 comentarios
Respuesta aceptada
Andrei Bobrov
el 8 de Jun. de 2017
[~,ii] = ismember(A.num,B.num);
B_sorted_as_A = B(ii,:);
0 comentarios
Más respuestas (1)
Guillaume
el 8 de Jun. de 2017
sorting A according to B:
[isinB, whereinB] = ismember(tableA.num, tableN.num);
assert(all(isinB), 'some rows of A are not found in B);
[~, order] = sort(whereinB);
sortedtableA = tableA(order, :);
0 comentarios
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!