Impose a numerical limit on the value of a sum of two vectors
Show older comments
Hello everyone
I want to sum two arrays, let's say a1 and a2. However, I seek that the sum, element by element, of these vectors does not exceed the maximum value of the array a1. Those elements of the sum vector that exceed this limit, I would like them to show the maximum of a1 as a numerical value.
How could I do this?
Accepted Answer
More Answers (2)
KSSV
on 16 Jul 2021
a12 = a1+a2 ;
[val,idx] = max(a1)
a12(a12>val) = []
Jayant Gangwar
on 16 Jul 2021
It is my understanding that you would like to sum two arrays element by element and replace all the elements in the resulting array that are greater than the max element in first array by that max element. Given below is an example where I have done the same with two dummy arrays.
a=1:10;
b=1:10;
ans=a+b;
m=max(a);
ans(ans>m)=m
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!