Expanding a matrix using interpolation?

18 vues (au cours des 30 derniers jours)
Claudio Duarte Silva
Claudio Duarte Silva le 29 Avr 2018
Hi everyone,
I have a 7X5 matrix called "Temperatures", and I was wondering if I could interpolate these values it both directions to get a better 2D temperature gradient graph?
This are the values in my matrix:
And using ">> imagesc(Temperatures)" I get something like this
Is it possible to interpolate this matrix to obtain a better temperature gradient graph?
Thank you!

Réponse acceptée

John D'Errico
John D'Errico le 29 Avr 2018
Modifié(e) : John D'Errico le 29 Avr 2018
Simplest is to use imresize. I assume it used to be in the image processing TB, but has migrated to MATLAB itself, due to the general utility of that function.
T = [ 300 300 300 300 300
300 346.3 358.9 346.3 300
300 363.8 380.5 363.8 300
300 356.8 373.2 356.8 300
300 363.8 380.5 363.8 300
300 346.3 358.9 346.3 300
300 300 300 300 300];
Tnew = imresize(T,30,'bilinear');
pcolor(Tnew)
shading interp
Given the coarse starting array, it does not merit more that that. Be careful with the bicubic option with imresize here.
Another option is to use interp2.
Tnew = interp2(T,5,'bicubic');
surf(Tnew)
shading interp
To be honest, your array may be far too coarse to merit that treatment.
  1 commentaire
Claudio Duarte Silva
Claudio Duarte Silva le 29 Avr 2018
Thank you very much! :)

Connectez-vous pour commenter.

Plus de réponses (1)

Ameer Hamza
Ameer Hamza le 29 Avr 2018
Modifié(e) : Ameer Hamza le 29 Avr 2018
Use interp2(), as follow
newNumberOfRows = 10; % set the number of rows interpolated rows you want
newNumberOfCols = 5; % set the number of columns interpolated rows you want
[x, y] = meshgrid(1:size(A,2), 1:size(A,1));
[xq, yq] = meshgrid(linspace(1, size(A, 2), newNumberOfCols), linspace(1, size(A, 1), newNumberOfRows));
newMatrix = interp2(x, y, A, xq, yq)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by