How to create a function which takes one column of data as its input and another as its output

6 ビュー (過去 30 日間)
I have two columns of data and need to come up with a function that take as input the values from the first column of data and outputs the corresponding values in the second column. There is no equation that links the columns together they are just two lines of data. How would I go about coming up with a function that enables me to input a value from the first column and be given the corresponding value in the second?
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 2 月 27 日
"... outputs the corresponding values in the second column."
You want to store the output in the second column, over-writing the values present there?
Gabriel
Gabriel 2023 年 2 月 27 日
No so for example column 1 row 6 will correspond to column 2 row 6 and column 1 row 10 corresponds to column 2 row 10. I need a function that allows me to input the values in column 1 and get the value next to it in column 2 as my output. I hope that makes sense

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

採用された回答

David Hill
David Hill 2023 年 2 月 27 日
Just use the find function. find
rng(1)
A=randi(100,10,2)
A = 10×2
42 42 73 69 1 21 31 88 15 3 10 68 19 42 35 56 40 15 54 20
f=A(find(A(:,2)==88),1)
f = 31
  3 件のコメント
Stephen23
Stephen23 2023 年 2 月 27 日
Logical indexing is simpler than FIND:
rng(1)
A = randi(100,10,2)
A = 10×2
42 42 73 69 1 21 31 88 15 3 10 68 19 42 35 56 40 15 54 20
V = 88;
Z = A(A(:,2)==88,1)
Z = 31

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by