Comapring Values in one Matrix to another

1 visualización (últimos 30 días)
Chris Stout
Chris Stout el 8 de Ag. de 2020
Comentada: Alan Stevens el 8 de Ag. de 2020
I have two matrixes
A = [373 383 393 403 413 420 451 485 499] ; B = [373 453 457 461 464]
I want two compare each value of A to every value of B and create a new matrix which is a collection of all the values of A which are bigger than at least one value in B
For example, I want to compare 383 from A to every value in B, and since its bigger than 373 in B I want to store it in a new matrix say called C.
I want to do this for every element in A
How can I do this?
Any help appreciated.

Respuestas (3)

Stephen23
Stephen23 el 8 de Ag. de 2020
Editada: Stephen23 el 8 de Ag. de 2020
The simple MATLAB way:
>> A = [373,383,393,403,413,420,451,485,499];
>> B = [373,453,457,461,464];
>> C = A(A>min(B))
C =
383 393 403 413 420 451 485 499

Alan Stevens
Alan Stevens el 8 de Ag. de 2020
What about:
A = [373 383 393 403 413 420 451 485 499] ; B = [373 453 457 461 464];
k = 1;
for i = 1:length(A)
t = A(i);
if any(t>B)
C(k) = t;
k = k+1;
end
end

Star Strider
Star Strider el 8 de Ag. de 2020
Another approach:
A = [373 383 393 403 413 420 451 485 499];
B = [373 453 457 461 464];
C = ones(numel(B),1)*A; % Expand ‘A’
C = C.' .* (A(:)>B); % Multiply By Logical Array
C = unique(C); % Create Vector Of Unique Values
.

Categorías

Más información sobre Line Plots 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!

Translated by