# How plot 4D data?

123 vues (au cours des 30 derniers jours)
Ali Almakhmari le 14 Oct 2021
Commenté : Kevin Holly le 14 Oct 2021
Lets say that I have the following data and I would like to plot the function f that is dependent on x, y, and z, In other words, f(x, y, z). How can I do that? x, y, z, and f(x, y, z) are variables that are eventually made of 10 by 10 by 10, for example:
x = 0.1:0.01:0.19;
y = 0.1:0.01:0.19;
z = 0.1:0.01:0.19;
f = x.*exp(x.^2 + y.^2 + z.^2);
I tried doing this and it failed:
[X, Y, Z] = meshgrid(x, y, z);
surf(X, Y, Z, f);
colorbar;
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

KSSV le 14 Oct 2021
x = 0.1:0.01:0.19;
y = 0.1:0.01:0.19;
z = 0.1:0.01:0.19;
[x,y,z] = meshgrid(x,y,z) ;
f = x.*exp(x.^2 + y.^2 + z.^2);
figure
hold on
for i = 1:size(x,3)
surf(x(:,:,i),y(:,:,i),z(:,:,i),f(:,:,i))
end
view(3)
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Kevin Holly le 14 Oct 2021
ah, you beat me and had a better result
x = 0.1:0.01:0.19;
y = 0.1:0.01:0.19;
z = 0.1:0.01:0.19;
[X, Y, Z] = meshgrid(x, y, z);
f = X.*exp(X.^2 + Y.^2 + Z.^2);
slice(f,5,5,5)
colorbar

Connectez-vous pour commenter.

### Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by