How plot 4D data?

126 views (last 30 days)
Ali Almakhmari
Ali Almakhmari on 14 Oct 2021
Commented: Kevin Holly on 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;

Accepted Answer

KSSV
KSSV on 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)
shading interp
And the use isosurface, slice. Read about them.
  1 Comment
Kevin Holly
Kevin Holly on 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

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!