Effacer les filtres
Effacer les filtres

How can I use interp1 to interpolate the last row of a matrix?

3 vues (au cours des 30 derniers jours)
Shreshtha Chaturvedi
Shreshtha Chaturvedi le 17 Déc 2022
Réponse apportée : Voss le 17 Déc 2022
I have the following 4 x 3 matrix:
A = [1,2,3;4,5,6;7,8,9;10,11,12]
I want to interpolate the rows of this matrix and get a 5 x 3 matrix to just get a single, last interpolated row. I am not sure how to use interp1 to this end. Can someone please help? Thank you!

Réponse acceptée

Voss
Voss le 17 Déc 2022
Here's my guess at what you mean:
A = [1,2,3;4,5,6;7,8,9;10,11,12]
A = 4×3
1 2 3 4 5 6 7 8 9 10 11 12
N = size(A,1);
A(N+1,:) = interp1(1:N,A,N+1,'linear','extrap')
A = 5×3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Plus de réponses (1)

Bora Eryilmaz
Bora Eryilmaz le 17 Déc 2022
Modifié(e) : Bora Eryilmaz le 17 Déc 2022
Interpolation is probably not the right term here since interpolation, typically, requires a set of (x,y) data and a different set of x values to use for finding interpolated y values.
A simple approach could be to use the column means of the A matrix to find the row of average values:
A = [1,2,3;4,5,6;7,8,9;10,11,12]
A = 4×3
1 2 3 4 5 6 7 8 9 10 11 12
A(end+1,:) = mean(A)
A = 5×3
1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000 11.0000 12.0000 5.5000 6.5000 7.5000

Catégories

En savoir plus sur Interpolation of 2-D Selections in 3-D Grids dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by