Interpolation of a matrix in 2D for complex numbers

Hello
I have a 3D matrix of a field E_x_y_t. say it's 600 x 700 x 2048 (correlated to x y and t)
At some point I'm deleting part of the Field in x and y. No need to touch T:
E_x_y_t([1:length(x)/4, length(x)/4+length(x)/2+1:length(x)],:,:) = [];
E_x_y_t(:,[1:length(y)/4, length(y)/4+length(y)/2+1:length(y)],:) = [];
x = [x(length(x)/4+1:length(x)/4+length(x)/2)];
But what I really need is from this point to make X and Y again 600 x 700 on all the T. (make interpolation of the complex 2d field for each value of time (T) to smaller grid for better resolution).
How can I do it? using interp2 somehow i guess?

Respuestas (2)

KSSV
KSSV el 25 de Mayo de 2023
You may use imresize.
Let A be your complex matrix:
B = imresize(A,2) ; % this makes double the size of A, you can specify the dimensions also
You can also use interp2.
[m,n,p] = size(A) ;
[X,Y] = meshgrid(1:n,1:m) ;
[Xi,Yi] = meshgrid(linspace(1,n,100),linspace(1,m,100)) ; % give your desired numbers instead of 100
Br = zeros(100,100,p) ;
Bc = zeros(100,100,p) ;
for i = 1:p
Br(:,:,i) = interp2(X,Y,real(A(:,:,i)),Xi,Yi) ;
Bc(:,:,i) = interp2(X,Y,imag(A(:,:,i)),Xi,Yi) ;
end
B = Br+1i*Bc ;

4 comentarios

elis02
elis02 el 25 de Mayo de 2023
doesn't work.
I have 3D matrix with known values.
E_x_y_t
the final should also remain 3D.
and if i have 3mm for example dia in the cross section for x, it should remain after the interpolation as well.
think of a small gaussian, that i have 10 pixels in x and y but also i have the development in time in the third dimension.
for each segment of the time, the 10 pixels i want to make them 600 pixels and preserve the value of the real and phse. if i had 3mm beam diameter for the 10 pixels, if i plot it in the 600 pixels i will also get it. But now with higher resolution.
KSSV
KSSV el 25 de Mayo de 2023
It should work...attach your data.
elis02
elis02 el 25 de Mayo de 2023
Editada: elis02 el 25 de Mayo de 2023
attaching the code.
see line 224.
the next lines is why i need this :-)
The relavent variable is E_x_y_t.
So to solve it I'm using interp2 right now:
E_x_y_t([1:length(x)/4, length(x)/4+length(x)/2+1:length(x)],:,:) = [];
E_x_y_t(:,[1:length(x)/4, length(x)/4+length(x)/2+1:length(x)],:) = [];
x = [x(length(x)/4+1:length(x)/4+length(x)/2)];
xq = linspace(x(1),x(end),650);
E_new = zeros(length(xq),length(xq),length(T));
for index = 1:length(T)
E_new(:,:,index) = interp2(x,x.',E_x_y_t(:,:,index),xq,xq.');
end
E_x_y_t = E_new;
clear E_new

Iniciar sesión para comentar.

elis02
elis02 el 27 de Mayo de 2023
To solve this i'm using interp2 right now.
E_x_y_t([1:length(x)/4, length(x)/4+length(x)/2+1:length(x)],:,:) = [];
E_x_y_t(:,[1:length(x)/4, length(x)/4+length(x)/2+1:length(x)],:) = [];
x = [x(length(x)/4+1:length(x)/4+length(x)/2)];
xq = linspace(x(1),x(end),650);
E_new = zeros(length(xq),length(xq),length(T));
for index = 1:length(T)
E_new(:,:,index) = interp2(x,x.',E_x_y_t(:,:,index),xq,xq.');
end
E_x_y_t = E_new;
clear E_new

Categorías

Más información sobre Interpolation en Centro de ayuda y File Exchange.

Preguntada:

el 25 de Mayo de 2023

Respondida:

el 27 de Mayo de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by