Finding X value corresponds to a particular Y value?

24 Ansichten (letzte 30 Tage)
Gaya V
Gaya V am 15 Jul. 2013
Kommentiert: Image Analyst am 29 Aug. 2023
I have a matrix , X=[5 6 9 8 4] Y=[8 7 2 1 9] If I plot this and I need to get position of the X value corresponds to Y=1, that means in which row the X value 8 is located? answer should be 4th position. How do I find this if the size of matrix is very big.. Please help me
  2 Kommentare
Pooja Patel
Pooja Patel am 29 Aug. 2016
value = find(Y == Y); xaty = x(value) or u can take find(Y == 1) this will also work if size is big
Guillaume
Guillaume am 29 Aug. 2016
@Pooja Patel
value = find(Y == Y)
That is exactly the same as
value = 1:numel(Y)

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Andrei Bobrov
Andrei Bobrov am 15 Jul. 2013
X=[5 6 9 8 4];
Y=[8 7 2 1 9];
idx = find(Y == 1);
Xidx = X(idx);
  3 Kommentare
Thomas
Thomas am 29 Aug. 2023
Thanks Andrei Bobrov level 9 MVP on 15 Jul 2013! I was able to finish my code for homework because of you!
Image Analyst
Image Analyst am 29 Aug. 2023
@jop schilder you would do that this way
mask = (Y == 1) | (Y == 2) | (Y == 7); % Logical vector (Only 0's and 1's)
indexes = find (mark) % Vector of actual index locations (e.g. [39, 123, 348, 983, 8943, ....etc.]

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by