Search and Compare Arrays
조회 수: 1 (최근 30일)
이전 댓글 표시
if I have the following Matrices:
MATRIX A: Column 1 = Temperatures; Column 2 = Coefficients;
MATRIX B: Temperatures
I need to Program Matrix_C to do the following:
For j=1:max(size(Matrix_B))
Matrix_C(j) =
For each temperatures in Matrix_B(j) it will retrieve the correct Coefficient from Matrix A
end
I hope I made sense
Thanks!
댓글 수: 0
채택된 답변
Matt Fig
2012년 8월 23일
편집: Matt Fig
2012년 8월 23일
I assume the temperatures in B exactly match those in A? In other words, you are not interpolating. First the FOR loop you request:
% Sample data.
A = [(1:20).',sort(round(rand(20,1)*1000)/100)]
B = [5;6;12]
% Fill C.
C = zeros(size(B));
for ii = 1:length(B)
C(ii) = A(A==B(ii),2);
end
But now look at an easier way:
C = interp1(A(:,1),A(:,2),B)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!