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

6 visualizzazioni (ultimi 30 giorni)
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)

Risposta accettata

Dyuman Joshi
Dyuman Joshi il 21 Ott 2023
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

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by