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

2 次查看(过去 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 CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by