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

1 view (last 30 days)
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

Accepted Answer

dpb
dpb on 24 Jun 2021
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.

More Answers (1)

Cris LaPierre
Cris LaPierre on 24 Jun 2021
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.

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!