Interpolation for n-dimensional array data
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I have this function in which I calculate Uvals,Svals and Vvals and store them in array. In this case I have 4D data. I have attached the .mat file.
rho_grid=[-1,0,1];
Nrho=length(rho_grid);
for i=Nrho:-1:1
rho1=rho_grid(i);
for j=Nrho:-1:1
rho2=rho_grid(j);
[Uvals(:,:,j,i),Svals(:,:,j,i),Vvals(:,:,j,i)]= svd(pro(rho1,rho2)); % two 'for' loops for 2 parameters 'rho1' and 'rho2' How to automate this for 'n' parameters?
end
end
I would like to retrieve entries of Uvals, Svals and Vvals like function of 2 variables 'rho1' and 'rho2'.
U = @(rho1,rho2) Uvals(...);
S= @(rho1,rho2) Svals(...);
V= @(rho1,rho2) Vvals(...);
Should I be using 'interp2' function for this? If have n-dimensional data, how can i make use of 'interpn' in my code? I had previously asked question in this context(https://de.mathworks.com/matlabcentral/answers/497657-accessing-function-output-for-different-values-of-variable?s_tid=prof_contriblnk), but I seek your help again. Thank you.
0 comentarios
Respuestas (2)
Christine Tobler
el 22 de En. de 2020
I don't think interpn would work very well for you: The U, S and V matrices returned by SVD are not linearly dependent on the input matrix to SVD, so linearly interpolating U, S, and V based on some grid points will not give the U, S and V of the matrix for a given set of points rho1 and rho2.
I think the only reliable way to do this is to just call svd(pro(rho1, rho2)) inside of those function handles.
What's the background for wanting to compute the SVD on some grid of rho1 and rho2 ahead of time? Is this to reduce computation time in the three function handles? If you can give some information about how you're planning to use those function handles, that would be helpful. For example: Do you always call all three of them? Do you call them many times for values rho1 and rho2 that are on grid points? For scattered values of rho1 and rho2?
1 comentario
Sindar
el 22 de En. de 2020
check out griddedInterpolant, I think it'll do what you want
2 comentarios
bassant tolba
el 30 de Oct. de 2020
please, I have (a mat dataset ) which has the shape (80000,72,14,1)
I need to upsample the width and height of it , I mean I need to double 72 and double 14
and save the upsampled data in mat format also.
please how can i do it ??
Sindar
el 30 de Oct. de 2020
interpn (or interp3 with same syntax):
% load in you data; you'll need to adjust these two lines
d=load('data.mat');
V=data.data;
% get number of points in each dimension, should be 80000,72,14
[Nx,Ny,Nz]=size(V);
% define a uniformly-spaced grid
[x,y,z] = ndgrid(1:Nx,1:Ny,1:Nz);
% Now, create the query grid with double the points in Y and Z:
[xq,yq,zq] = ndgrid(1:Nx,1:0.5:Ny,1:0.5:Nz);
% Interpolate V at the query points.
Vq = interpn(x,y,z,V,xq,yq,zq);
% Save the new data to a mat-file
save('data_finer.mat','Vq','xq','yq','zq')
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!