Including interpolation row by row in a matrix using a for loop
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
dpb
il 24 Giu 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.
0 Commenti
Più risposte (1)
Cris LaPierre
il 24 Giu 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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Interpolation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!