Finding the value of one column based on another column

I have an (n,6) matrix where the first column is time and the 2:6 columns are cumulative sums through time. I'd like to know the time value in column 1 where the cumulative sum values in column 2:11 are equal to 0.5.
To help visualize this, I attached a figure. I'm essentially trying to find where on the x axis, each one of those distributions crosses the dashed line (at y=0.5).
Any ideas?
Sorry if some of my language is unclear...I'm neither a programmer or statistician!
Andy

 Risposta accettata

[ii,jj]=find(A(:,2:6)==0.5)
out=A(ii,1)

4 Commenti

But I will suggest
[ii,jj]=find(abs(A(:,2:6)-0.5)<0.001)
out=A(ii,1)
Thank you, Azzi that got me really close to my solution, but not quite there.
So an issue is that there really isn't an exact 0.5 value in the cumulative sum columns (i.e. A(:,2,6))...the sequence may look something like this:
...0.4715, 0.4976, 0.5217, 0.5441...
I suppose there is a way to interpolate linearly between the points, but I'm not sure I need that resolution for what I'm doing. I think I can just the value in each column closest to 0.5.
Modifying your code slightly, this is what I've come up with:
[ii,jj]=find(min(abs(A(:,2:6)-0.5)))
out=A(ii,1)
Unfortunately, the row output (ii) ends up being all 1s and not the rows where the minimums are observed. Should be [12, 16, 66, 61, 43] looking at it manually. Not sure where I've gone astray...
[min_val,ii]=min(abs(A(:,2:6)-0.5))
out=A(ii,1)
That's it!
Thank you so much for your help!

Accedi per commentare.

Più risposte (0)

Categorie

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by