How to compare two arrays to find in which column a value from one array is greater than value of other array
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jeroen
el 21 de Oct. de 2023
Comentada: Jeroen
el 21 de Oct. de 2023
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)
0 comentarios
Respuesta aceptada
Dyuman Joshi
el 21 de Oct. de 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)
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!