How to interpolate 2D array from 3D array?

1 vue (au cours des 30 derniers jours)
piston_pim_offset
piston_pim_offset le 15 Déc 2023
Déplacé(e) : Image Analyst le 29 Déc 2023
A=[3 4 5 6 7];
numel(X)=23;
numel(Y)=42;
There are 5 different contour data with respect to X and Y like the one belove. I have 5 different contour data of 23x42, together a 3D array of 5x23x42. There are data for the given values of A, but l need data for interpolated values of A, for example in the case of A=4.7. Then l'll plot the data corresponding to the calculated value of A.
Thanks for your help!
  4 commentaires
Torsten
Torsten le 15 Déc 2023
Modifié(e) : Torsten le 15 Déc 2023
I don't completely understand your question.
You have contour data on an x/y/z grid of size 5x23x42 and you have a value in between the 5 x-coordinates and you want to interpolate your 5x23x42 contour data to this value to get back a 23x42 matrix ?
piston_pim_offset
piston_pim_offset le 15 Déc 2023
Yes, exactly. I have and contour plot of 23x42, and there are 5 of them wrt. 5 different values. I want to get interpolated interpolated data for every possible value of X.

Connectez-vous pour commenter.

Réponses (3)

piston_pim_offset
piston_pim_offset le 15 Déc 2023
Modifié(e) : piston_pim_offset le 15 Déc 2023
AI Chat Playground gave me this answer with an error:
contourData = randn(5, 23, 42);
A = [3 4 5 6 7];
interpContourData = interp1(A, contourData, 4.7);
[X, Y] = meshgrid(1:size(interpContourData, 2), 1:size(interpContourData, 3));
contourf(X, Y, squeeze(interpContourData), 20);
Error using contourf
The size of X must match the size of Z or the number of columns of Z.

Dyuman Joshi
Dyuman Joshi le 15 Déc 2023
Déplacé(e) : Image Analyst le 29 Déc 2023
Try this. Though I have no idea if it does what you asked for or not.
contourData = randn(5, 23, 42);
A = [3 4 5 6 7];
interpContourData = interp1(A, contourData, 4.7);
[X, Y] = meshgrid(1:size(interpContourData, 2), 1:size(interpContourData, 3));
interpContourData = permute(interpContourData, [3 2 1]);
contourf(X, Y, squeeze(interpContourData), 20)
  1 commentaire
piston_pim_offset
piston_pim_offset le 18 Déc 2023
Déplacé(e) : Image Analyst le 29 Déc 2023
Much thanks, it worked.

Connectez-vous pour commenter.


Torsten
Torsten le 15 Déc 2023
Déplacé(e) : Torsten le 15 Déc 2023
contourData = randn(5, 23, 42);
x = 1:5;
y = 1:23;
z = 1:42;
X = [2.6 4.7];
contourData_interpolated = zeros(numel(X),23,42);
for j = 1:23
for k = 1:42
contourData_interpolated(:,j,k) = interp1(x,squeeze(contourData(:,j,k)),X);
end
end

Catégories

En savoir plus sur Matrices and Arrays 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