How can i find the maximum of three variables?
231 次查看(过去 30 天)
显示 更早的评论
Hi, I have to find the maximum of three variables A, B, C and store the result in D. thanks
回答(5 个)
Jan
2012-11-27
How would you find the maximum of two variables?
docserach maximum
Then if you have the maximum of two variables, you can compare it to the third one.
0 个评论
Image Analyst
2012-11-27
In general, for A, B, and C being numerical arrays of any size (possibly different than each other):
% Define 3 double matrixes of different sizes
A = rand(3);
B = rand(4);
C = rand(5);
% Now get the max overall
D = max([A(:), B(:), C(:)]) % Note use of (:) to turn arrays into vectors.
If they're cell arrays or structures though, let us know because that would be different.
1 个评论
Jan
2012-11-28
If A, B, C hav different sizes, [A(:), B(:), C(:)] fails. But [A(:); B(:); C(:)] with the semicolons for vertical concatenation works.
Sarah Crimi
2018-10-5
编辑:Sarah Crimi
2018-10-5
if it is vectors of different sizes, you would have to do max(max(a),max(b)),max(max(b),max(c)). So, it takes max of the first and second vectors and compares the values, and max of the second and third vectors, then takes the max of those two numbers.
2 个评论
Sarah Crimi
2018-11-16
编辑:Sarah Crimi
2018-11-16
Oh yes, I see. This makes it into one vector then takes the max.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!