I have two sets
X Y
1 2
3 6
4 7
5 8
I have to find highest value in category Y which is 8, after finding that 8 is the highest value I have to call value 5 in category X to from a matrix [ 5 8].
I know how to find the largest value, but I don’t know how to call 5 from X category.
Please can someone help me in call the specified value.

 採用された回答

galaxy
galaxy 2019 年 10 月 25 日

1 投票

Let 's try
X = [1 3 4 5];
Y = [2 6 7 8];
[max_val, idx] = max(Y);
X_idx = X(idx);

7 件のコメント

sampath kumar punna
sampath kumar punna 2019 年 10 月 25 日
Y
1 3
5 6
3 2
7 9
8 5
if Y is matrix , in the the second column we have values 2 and 5 , i want to call the row which is having value 2 and 5 in second column and from a new matrix
[ 3 2
8 5 ]
like this
galaxy
galaxy 2019 年 10 月 25 日
out = Y(find(Y(:,2) == 2 | Y(:,2) == 5 ), :);
Please accept my answer.
sampath kumar punna
sampath kumar punna 2019 年 10 月 25 日
Y = [1 7
3 9
11 12
15 18
22 12
12 23
15 19
10 22
17 28
111 123]
z= [ 9 12 18 12 23 19 22 28 123]
for i= 1: length(z)
out(i) = Y(find(Y(:,2) == z(:,i)))
end
this code shows some error can you fix this
galaxy
galaxy 2019 年 10 月 25 日
I can't believe that after I anwser for you, you accept your anwser.
I think you are unkind person. So I will not support you even it is very easy.
sampath kumar punna
sampath kumar punna 2019 年 10 月 25 日
im really sorry galaxy, i din't know that i have accepted my answer i thought i accepted your, i just saw my mistake and removed mine and accpected your. accepting my answer was not intentional, hope you understand.
sampath kumar punna
sampath kumar punna 2019 年 10 月 25 日
by any chance can you fix this error
Y = [1 7
3 9
11 12
15 18
22 12
12 23
15 19
10 22
17 28
111 123]
z= [ 9 12 18 12 23 19 22 28 123]
for i= 1: length(z)
out(i) = Y(find(Y(:,2) == z(:,i)))
end
this code shows an error while executing (Unable to perform assignment because the left and right sides have a different number of
elements.)
can anyone please fix this error
thanks
galaxy
galaxy 2019 年 10 月 25 日
Let 's try:
find_idx = find(Y(:,2) == z(1));
for i= 2: length(z)
find_idx = vertcat(find_idx, find(Y(:,2) == z(i)));
end
out = Y(unique(find_idx), :);
you can try with other z:
example:
z= [ 9 12 18];
out =
3 9
11 12
15 18
22 12

サインインしてコメントする。

その他の回答 (1 件)

sampath kumar punna
sampath kumar punna 2019 年 10 月 25 日

0 投票

what if i have to call 7 from y and 4 from x

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2019 年 10 月 25 日

コメント済み:

2019 年 10 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by