How to compare two arrays to find in which column a value from one array is greater than value of other array

5 ビュー (過去 30 日間)
I want to compare values out of same column of different arrays (of different size) and then to kwow at which column a value of one array is greater than value of other array. The first comparisson are between the values of the first column. The second comparisson are between te values of the second column, and so forth.
Voor instance:
A = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
B = [1, 2, 3, 5, ,8, 13, 21]
At which column is B > 2 * A.
Here the answer will be 6 (because in the 6th column is 13 > 2 * 6 and thus is the first column from left to right were B > 2*A)

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 10 月 21 日
A = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
B = [1, 2, 3, 5, 8, 13, 21];
n = min(numel(A),numel(B));
%Comparison
com = B(1:n)>2*A(1:n);
%Find the index first occurence where comparison is true
idx = find(com, 1)
idx = 6

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by