4D function plot
Ältere Kommentare anzeigen
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;
Antworten (4)
Akira Agata
am 26 Mai 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

1 Kommentar
Nisha Dhake
am 6 Jun. 2017
Bearbeitet: Nisha Dhake
am 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:

John D'Errico
am 26 Mai 2017
0 Stimmen
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.
Naveen Pathak
am 19 Okt. 2018
Bearbeitet: Naveen Pathak
am 19 Okt. 2018
0 Stimmen
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.
Kategorien
Mehr zu Lighting, Transparency, and Shading finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!