using if to find a value in one variable, but then give you the value of a second variable

1 view (last 30 days)
Hi all,
Ok so I have river runoff data for around 100 days, and I would lke to find the time of maximum runoff on each day. I reshaped the data (Q) into an x,y matrix (hours,days), but so far have had no luck getting the code to work. I tried it first with made up data and the code below worked fine:
for x=1:24;
for y=1:4;
if Q(x,:)==max(y)
Peak=T(x,:);
end
end
end
The variable T is matrix of the time with 1:24 repeated for each day. Peak is the variable of time of maximum runoff.Trouble is I can't get this to work with my real data, I have already taken out the NaNs and replaced them with 1. There is no error it just runs through without making Peak. I found the maximum for each day sepeately and it works fine for days without NaNs. Any ideas??
I would be greatful for any suggestions, Thanks, Cat

Accepted Answer

Oleg Komarov
Oleg Komarov on 16 Apr 2012
[val,idx] = max(Q)
This is the row-wise maximum, i.e. along the rows for each column. idx says on which row the max is found. Since each day is a different column, the idx tells you which hour.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!