
4D function plot
13 views (last 30 days)
Show older comments
I have a function of 3 variables like V= f(r1,p,r2), I want to plot these 4 data in one graph to be able to capture behavior of V with respect to all three variables. I searched a little bit and read about Sliceomatics but not sure how does it work and if it deliveres my requirements. I would appreciate if someone could suggest a way for it. As an example lets say I have: r1 = [1 2 3 4 5 6]; p = [2 4 5 8 9 7]; r2 = [10 45 1 0 7 9]; v= 5.*r1.^2+2.*p.^2+r2.^2;
0 Comments
Answers (4)
Akira Agata
on 26 May 2017
Using isosurface function, you can do somehow this type of plot. In the following code, I plotted the surfaces of func(x,y,z) = 0.5 (red) and 0.8 (green).
func = @(x,y,z)(sin(2*x.^2+2*y.^2).*cos(2*z.^2));
[x,y,z] = meshgrid(-1:0.1:1, -1:0.1:1, -1:0.1:1);
v = func(x,y,z);
figure
p1 = patch(isosurface(x,y,z,v,0.5));
hold on
p2 = patch(isosurface(x,y,z,v,0.8));
isonormals(x,y,z,v,p1);
isonormals(x,y,z,v,p2);
p1.FaceColor = 'red';
p2.FaceColor = 'green';
p1.EdgeColor = 'none';
p2.EdgeColor = 'none';
daspect([1,1,1])
view(3); axis tight
camlight
lighting gouraud

Nisha Dhake
on 6 Jun 2017
Edited: Nisha Dhake
on 6 Jun 2017
A simple solution will be to keep shifting the array while using the 'hold on' function.
Here is how you can do it:
r1 = [1 2 3 4 5 6]';
p = [2 4 5 8 9 7]';
r2 = [10 15 1 0 7 9]';
for x=0:length(p)
p=circshift(p,1);
for w=0:length(r2)
r2=circshift(r2,1);
for u =1:1:length(r1)
v(u)=5*r1(u)^2+2*p(u)^2+r2(u)^2;
end
scatter3(r1,p,r2,40,v,'filled')
xlabel('r1')
ylabel('p')
zlabel('r2')
hold on
end
end
cb = colorbar;
The plot you will get will be:

0 Comments
John D'Errico
on 26 May 2017
You cannot visualize 4-d data in a 2-d plot. And a plot is only 2 dimensions. Even a 3-d plot only makes sense if you rotate things around, or view it using stereo vision. But 4-d simply does not work.
So the classic trick is to use slices in the form of an isosurface. But isosurfaces only are implemented if you have a regular, meshed grid of points, thus a 3-d array in the form of v(x,y,z).
But you have scattered data in 4 dimensions. So nothing will work until you turn that into something regular and well connected. Scattered points are just that, isolated, with no simple way to know what is near what.
0 Comments
Naveen Pathak
on 19 Oct 2018
Edited: Naveen Pathak
on 19 Oct 2018
The solution of Akira Agata will certainly work for you. Just add one more line to represent everything in a transparent manner so that volume can be visualized. Just include an another line: alpha(n), where "n" is some value between 0 to 1. Try, n = 0.3 or 0.4 etc.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!