How to get the max value between two elements of two separate arrays?

31 次查看(过去 30 天)
Hello everyone, thanks for reading
What I'm trying to do is this:
I have these two arrays:
a= [1,3,4,6]
b= [2,2,5,4]
I want to get a new 'c' array with the max values of a comparison between each element of 'a' and 'b'
this -----------> c= [2,3,5,6]

采纳的回答

Eric Delgado
Eric Delgado 2022-10-21
Try this...
a= [1,3,4,6];
b= [2,2,5,4];
max([a;b])
ans = 1×4
2 3 5 6

更多回答(1 个)

Stephen23
Stephen23 2022-10-21
The efficient MATLAB approach:
a = [1,3,4,6];
b = [2,2,5,4];
c = max(a,b)
c = 1×4
2 3 5 6

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by