two arrays mapping value

7 ビュー (過去 30 日間)
Pierre
Pierre 2013 年 9 月 25 日
Hi, I have two arrays A=[1 0.1452; 2.1 0.2487; 3.2 0.3478; 4.8 0.41123] and B=[0.4 0.5 2.5 3.5 1.7]. I wanna get the mapping value of B from A. The rule is to find the ceil value of B in first column of A and return value in second column of A.For example, the ceil value of 1.7 in first column of A is 2.1, so the mapping value is 0.2487. Finally, the mapping value of B is [0.1452 0.1452 0.3478 0.41123 0.2487]. The size of B is over 10000. Please tell me the faster and more efficient method to solve it. Thanks

採用された回答

Vishal Rane
Vishal Rane 2013 年 9 月 25 日
A((A(:,1) == min(A(A(:,1) > B(1)))),2)
  1 件のコメント
Vishal Rane
Vishal Rane 2013 年 9 月 25 日
編集済み: Vishal Rane 2013 年 9 月 25 日
run this in a for loop by indexing B(i) or use this
arrayfun( @(x)( A((A(:,1) == min(A(A(:,1) > x))),2)), B)

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

その他の回答 (1 件)

Jan
Jan 2013 年 9 月 25 日
編集済み: Jan 2013 年 9 月 25 日
B(B > max(A(:, 1)) = NaN; % B too large
[dummy, index] = histc(B, [-Inf, A(:, 1).']);
outOfRange = (index == 0)
Result = A(index(~outOfRange), 2);
I cannot test this currently. Please care about the exceptions like values of B, which are greater or equal the maximum value of A. The CEIL criterion is not fulfilled, when an element of B is exactly contained in A. But HISTC is the general way to go through.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by