finding the maximum value table A for values in table B bellow benchmark

1 ビュー (過去 30 日間)
Alexandra
Alexandra 2016 年 2 月 15 日
コメント済み: Guillaume 2016 年 2 月 15 日
So, here's the situation: I have three tables: A = [50 100 30 4]; B = [100 150 90 50]; C = [50 100 150];
Value in C are benchmarks and we need a table that gives for each value of C, the maximum value in A such that all values in B are bellow/equal the benchmark. That is: D = [4 50 100]; In B only 50 is bellow/equal to 50 so 4 the máximum in A. But for 100, 100/90/50 are all bellow equal to 100 so 50 is the máximum in A.
I am trying with a loop but it's not working. Thanks a lot.
  2 件のコメント
Alexandra
Alexandra 2016 年 2 月 15 日
You're right

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

採用された回答

Guillaume
Guillaume 2016 年 2 月 15 日
One possible way, assuming that values in A are always positive:
AA = repmat(A', 1, numel(C));
D = max(AA .* bsxfun(@le, B', C))
If you want it to work even with negative values in A, it's only slightly more complicated
AA = repmat(A', 1, numel(C));
D = max(AA .* (0./bsxfun(@le, B', C) + 1)) %0./x+1 change a logical matrix of [0, 1] into a matrix of [Nan, 1]
  3 件のコメント
Guillaume
Guillaume 2016 年 2 月 15 日
"Got this error: Error using bsxfun Non-singleton dimensions of the two input arrays must match each other."
Then, B or C are not vectors as in your question. At least one of them is 2D (or ND).

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

その他の回答 (0 件)

カテゴリ

Find more on Operators and Elementary Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by