find multiple maximum imaginary part
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, i have a 300x625 complex double, i need to find the Maximum imaginary part in each column, considering that each column contains multiple real parts that has the same maximum i need....?
camp = (ca2 + ca1f)/2; % 300x625 imaginary double
[Mcamp,m] = max(imag(camp));
McampY = Mcamp; % the Maximum imaginary
McampX = real(camp(m)); % the corresponding Real
if a column has 4 numbers that has the same maximum imaginary part, would the above code find them all ? i think it finds the first one only .....
0 commentaires
Réponse acceptée
dpb
le 17 Sep 2018
Yes,
[Mcamp,m] = max(imag(camp));
returns only the index m of the first element if there are multiple maxima in a column. To locate the rest you'll need to use
[rmxi,cmxi]=find(imag(camp)==Mcamp);
which will return the row,column indices of each element that matches the values in Mcamp.
2 commentaires
dpb
le 17 Sep 2018
Modifié(e) : dpb
le 17 Sep 2018
Attach the data; it works here on a test dataset.(*) We can't do anything with an image as far as debugging and only four significant digits are shown.
I'm guessing the other value isn't actually identically equal to but slightly smaller than the one identified as the maximum.
Try
imag(camp(127,221))==imag(camp(128,221))
and
imag(camp(127,221))-imag(camp(128,221))
and report back the results.
(*) For illustrative purposes as simple example--
>> x=[1 3;2 4;2 4]; % two values that match each column
xmx=max(x); % get the maxima of each column
[r c]=find(x==mx); % find locations that match
OK, what was the result?
>> [r c]
ans =
2 1
3 1
2 2
3 2
>>
We see that the two values in 2nd,3rd rows are equal to the maximum value for each of the two columns; result as expected.
Now let's try something...
>> x(3,2)=x(3,2)-eps(x(3,2)) % make just a little different but "look" same
x =
1.0000 3.0000
2.0000 4.0000
2.0000 4.0000
>> xmx=max(x);
>> [r c]=find(x==mx);
>> [r c]
ans =
2 1
3 1
2 2
>>
and lo! and behold! There's only one position actually identically equal to the max in the second column even though to the shown five significant digits at the command prompt they look to be the same.
>> x(2,2)-x(3,2) % How different are they?
ans =
8.8818e-16
>>
Not much different but they're not actually equal.
If you want values that are "close" but not identically equal to the maxima, then you'll need to use ismembertol.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!