フィルターのクリア

How do i retrieve a specific value from a 2D matrix?

1 回表示 (過去 30 日間)
David van Nederpelt
David van Nederpelt 2018 年 6 月 4 日
回答済み: Star Strider 2018 年 6 月 4 日
Hello,
I've a matrix from which I want to get a specific value based on earlier calculations. So I want the value of B matched with A based on earlier calculated values (Thus the value of B which belongs to A)
earliercalculatedvalue = value from a certain function
if true
A = [0, 2.5, 5, 7.5, 10, 12.5, 13.5, 15];
B = [0.0433512251001877, 0.043577394493621, 0.0439878459898567, 0.044652541077113, 0.0450839697675535, 0.0458295673490097, 0.0461248505159152, 0.0465317879404617];
Matrix = [A;B];
Wantedvalue=Matrix(A==earliercalculatedvalue,:);
end
Thanks very much in advance!
  2 件のコメント
Adam
Adam 2018 年 6 月 4 日
And what is wrong with your code specifically? What are you getting as Wantedvalue?
David van Nederpelt
David van Nederpelt 2018 年 6 月 4 日
I want the value of B where A=earliercalculatedvalue. For the wantedvalue i'm getting a 1D array but I want just the value of B belonging to A (for example the earlier calculated value=5 then the Wantedvalue should be: 0.0439878459898567)

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

採用された回答

Star Strider
Star Strider 2018 年 6 月 4 日
One approach:
earliercalculatedvalue = 5;
Wantedvalue = B(A == earliercalculatedvalue) % Simplest
Wantedvalue = interp1(A, B, earliercalculatedvalue,'linear','extrap') % More Robust
give the same result for both:
Wantedvalue =
0.043987845989857
Wantedvalue =
0.043987845989857

その他の回答 (1 件)

Honglei Chen
Honglei Chen 2018 年 6 月 4 日
You can use
B(A==earliercalculatedvalue)
HTH

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by