How to pick values in a matrix due to values in another matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Trond Oesten
el 3 de Mzo. de 2015
Comentada: Guillaume
el 3 de Mzo. de 2015
Hi,
I have two data sets (f and g) with 5 values in each and by using the tiedrank command I have ranked the lowest to the highest value in data set g. What I want to to is pick values in f that correspond to the ranked values in d. So I want to find where the value is 1,2, and so on in d and sample the value at the same index in matrix f. These values will be sampled in f_marked. Is there an easy way to do this in matlab?
clc; clear all; close all;
f = [1 5 9 8 2];
g = [2 4 1 5 7];
d = tiedrank(g);
d = [2 3 1 4 5];
f_marked = [9 1 5 8 2]; % my new sorted vector of f based on d
0 comentarios
Respuesta aceptada
Guillaume
el 3 de Mzo. de 2015
Editada: Guillaume
el 3 de Mzo. de 2015
[~, order] = sort(d);
f_marked = f(order);
Another option:
f_marked = accumarray(d', f)'
2 comentarios
Guillaume
el 3 de Mzo. de 2015
Indeed. I wasn't thinking clearly when I wrote my reply.
Edited answer that does give the correct result
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!