How do i retrieve a specific value from a 2D matrix?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
2018년 6월 4일
And what is wrong with your code specifically? What are you getting as Wantedvalue?
채택된 답변
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
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!