Getting incorrect indices with Max function

8 Ansichten (letzte 30 Tage)
Swapneal Jain
Swapneal Jain am 19 Apr. 2017
Kommentiert: Star Strider am 20 Apr. 2017
Hi, I'm scanning through a matrix and getting the maximum values in a odd interval (you'll see in my code) However my problem is that the indicies that I am getting are incorrect and strange, going backwards when the indicies should be going forwards.
b=1;
for i=1:2274876
if(mod(i,2)==0)
continue
end
[T(b),M(b)]=max(Y1(1+(i-1)*58:59+(i-1)*58));
b=b+1;
end
In my code Y1 is the matrix that I am scanning through and T is supposed to store the max points in that interval while M is supposed to give the indices corresponding. I was then going to take the indices and create another matrix that has all the X coordinate points relating to that indicy. Here's just the first 15 or so slots of M that I am receiving. As you can see from my code the interval shouldn't even have these values by the second iteration. Meaning that at the minimum my indicy should have went up by 59 at the next iteration.
1 46 33 24 20 53 48 41 58 5 3 23 8 23 28
Can anyone can point out what I'm doing wrong?
  2 Kommentare
Roger Stafford
Roger Stafford am 19 Apr. 2017
Also your intervals are overlapping. They go:
1:59, 59:117, 117:175, etc.
so 59, 117, etc each lie in two intervals.
Swapneal Jain
Swapneal Jain am 20 Apr. 2017
I see, thank you. I wouldn't have noticed that

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 19 Apr. 2017
The indices it returns are relative to the position of the maximum value in the argument vector, not the absolute index.
Example
v = rand(1, 15);
v(7) = 1;
[M(1),P(1)] = max(v);
[M(2),P(2)] = max(v(5:10));
Result = [M; P]
Result =
1 1
7 3
So you need to correct for the offsets in your argument vector ranges to get the absolute index values.
  2 Kommentare
Swapneal Jain
Swapneal Jain am 20 Apr. 2017
That makes things much clearer, thank you
Star Strider
Star Strider am 20 Apr. 2017
My pleasure.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by