find multiple maximum imaginary part

5 views (last 30 days)
Zen Has
Zen Has on 17 Sep 2018
Edited: dpb on 17 Sep 2018
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 .....

Accepted Answer

dpb
dpb on 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 Comments
Zen Has
Zen Has on 17 Sep 2018
dpd, thanks for your answer
i tested it, rmxi locates the row of 1 maximum value in each column, other 3 or 4 values are neglected.. (other real values that has the same maximum imaginary in the same column) Check pic for ex., the code finds only the value in row 128, and neglect the value with the same maximum in row 127
cmxi is 1 column that counts from 1 till 625
should i use a for loop which checks all 300 values in each columns and finds all the maximums and their corresponding reals ? if yes, how can i do it ?
dpb
dpb on 17 Sep 2018
Edited: dpb on 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.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!