필터 지우기
필터 지우기

Including interpolation row by row in a matrix using a for loop

조회 수: 2 (최근 30일)
Rahim Yousefi
Rahim Yousefi 2021년 6월 24일
답변: dpb 2021년 6월 24일
I have a Raman spectral data which contains 140 rows and 1317 columns.
The wavenumbers are in the range of 102-4050 with the resolution of 3.
I want to perform an interpolation to make the data set similar to a calibration data set which the
wavenumbers are in the range of 300-3425.
I have used interp1 as follow:
X = Ramandata
Wave_no_X = linspace(102,4050,1317);
Wave_no_intrest = linspace(300,3425,1000);
Interpolated = interp1(Wave_no_X, X, Wave_no_intrest);
However this would not work because X should only be a column vector X(1,:).
Therefore I tried a loop to pass all the rows of X through interp1. But the codeis not working. Could any one help?
[n,m] = size(X)
Interpolated = []
for i = 1: n
Interpolated(i) = interp1(Wave_no_X, (X(i,:)), Wave_no_intrest);
end

채택된 답변

dpb
dpb 2021년 6월 24일
What error? Looks like should be ok but didn't have data to try and didn't make up any...but should be able to use the vectorized form here
Wave_no_X = linspace(102,4050,1317);
Wave_no_intrest = linspace(300,3425,1000);
Interpolated = interp1(Wave_no_X, Ramandata.', Wave_no_intrest);
would give the interpolated array
A sample just random data of the same idea --
>> interp1(1:10,rand(10,3),3:9)
ans =
0.6845 0.3365 0.9711
0.7025 0.6972 0.7023
0.9285 0.4717 0.9040
0.1740 0.3085 0.3593
0.9693 0.1514 0.0041
0.7826 0.2067 0.9643
0.4238 0.1314 0.2428
>>
NB: the interpolated xq values must be within the range of the x values; interp1 will not extrapolate automatically.

추가 답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 6월 24일
You will likely find this example helpful. Just make your X values a column vector. You should transpose your Y values so each row corresponds to X. You can transpose the result back if you prefer to have the columns represent frequency.
X = linspace(102,4050,1317)';
Xq = linspace(300,3425,1000);
Interpolated = interp1(X, Ramandata', Wave_no_intrest)';
Note that this is untested, since you did not share your data.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by