フィルターのクリア

How to pick values in a matrix due to values in another matrix

1 回表示 (過去 30 日間)
Trond Oesten
Trond Oesten 2015 年 3 月 3 日
コメント済み: Guillaume 2015 年 3 月 3 日
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

採用された回答

Guillaume
Guillaume 2015 年 3 月 3 日
編集済み: Guillaume 2015 年 3 月 3 日
[~, order] = sort(d);
f_marked = f(order);
Another option:
f_marked = accumarray(d', f)'
  2 件のコメント
Trond Oesten
Trond Oesten 2015 年 3 月 3 日
This don't work. When I put f_marked = f(d) I get [5 9 1 8 2]. I should get [9 1 5 8 2]...
Guillaume
Guillaume 2015 年 3 月 3 日
Indeed. I wasn't thinking clearly when I wrote my reply.
Edited answer that does give the correct result

サインインしてコメントする。

その他の回答 (1 件)

Stephen23
Stephen23 2015 年 3 月 3 日
編集済み: Stephen23 2015 年 3 月 3 日
The simplest answer is to use d and f directly:
>> x(d) = f
x =
9 1 5 8 2
  1 件のコメント
Guillaume
Guillaume 2015 年 3 月 3 日

Indeed. I've got a cloudy mind today. Time to go home...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by