How to find corresponding x values for array of y values

6 views (last 30 days)
Hello,
I have imported data from an image processing software where I have a series of stacked x-y coordinates (from a stacked image). My raw data consists of one column of x-values and over 400 columns of y-values. In MatLab, I currently am able to produce a1x465 array with each minimum value of y from each y column. How can I find the cooresponding x-value for each min value of y?

Accepted Answer

Cris LaPierre
Cris LaPierre on 18 Feb 2021
Edited: Cris LaPierre on 18 Feb 2021
Use the following syntax
When you are taking the min of an mxn array, I is a vector containnig the row numbers of the minimum values. Use that to index into your column of X values.
x = [3;10];
[MN,I] = min(rand(2,3))
MN = 1×3
0.2223 0.2202 0.8156
I = 1×3
2 1 2
x(I)
ans = 3×1
10 3 10
  1 Comment
Meagan Rhyne
Meagan Rhyne on 18 Feb 2021
Thank you! That's exactly what I needed. I'm relatively new to MatLab and don't quite know what commands exist for these things. I appreciate your help!

Sign in to comment.

More Answers (1)

David Hill
David Hill on 18 Feb 2021
Assuming the first column is x and the remaining columns y of matrix M
[min,idx]=min(M(:,2:end));
x=M(idx,1);

Community Treasure Hunt

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

Start Hunting!