compare two vectors then insert missing element

조회 수: 1 (최근 30일)
james sinos
james sinos 2021년 4월 29일
답변: Stephen23 2021년 4월 29일
i have a matrix :
A=[ 1.000 0.5860 0.01403
2.500 0.7395 0.01277
3.500 0.8450 0.01146
4.000 0.8967 0.01173
4.500 0.9476 0.01215
5.000 0.9962 0.01280
6.000 1.0973 0.01367
6.500 1.1398 0.01457
7.000 1.1889 0.01515
8.000 1.2574 0.01915
8.500 1.2816 0.02234
9.500 1.3300 0.02731
10.500 1.3267 0.03649 ]
for the first column let say its
B=[ 1.000
1.500
2.000
2.500
3.500
4.000
4.500
5.000
5.500
6.000
6.500
7.000
7.500
8.000
8.500
9.000
9.500
10.000
10.500]
i want to compare A(:1) with b then insert missing rows to make A(:,1) = b , then perform interpolation for A(:,2) and A(:,3) new rows
thanks
  댓글 수: 1
Chunru
Chunru 2021년 4월 29일
Bq = sort(union(B, A(:,1))); % the query points are from B and A(:,1)
C = interp1(A(:, 1), A(:, 2:end), Bq); % Interpolation
C = [Bq C]; % The result

댓글을 달려면 로그인하십시오.

답변 (1개)

Stephen23
Stephen23 2021년 4월 29일
Simpler:
A=[ 1.000 0.5860 0.01403
2.500 0.7395 0.01277
3.500 0.8450 0.01146
4.000 0.8967 0.01173
4.500 0.9476 0.01215
5.000 0.9962 0.01280
6.000 1.0973 0.01367
6.500 1.1398 0.01457
7.000 1.1889 0.01515
8.000 1.2574 0.01915
8.500 1.2816 0.02234
9.500 1.3300 0.02731
10.500 1.3267 0.03649 ];
B = 1:0.5:10.5;
C = interp1(A(:,1),A,B(:))
C = 20×3
1.0000 0.5860 0.0140 1.5000 0.6372 0.0136 2.0000 0.6883 0.0132 2.5000 0.7395 0.0128 3.0000 0.7923 0.0121 3.5000 0.8450 0.0115 4.0000 0.8967 0.0117 4.5000 0.9476 0.0121 5.0000 0.9962 0.0128 5.5000 1.0467 0.0132

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by