Matlab plot 4D data

5 views (last 30 days)
Yi Liu
Yi Liu on 12 Oct 2022
Answered: Keita Abe on 12 Oct 2022
I want to plot 4d data on space x+y+z<=1,x>=0,y>=0,z>=0, so I use the following code
i=1;
for p=0:0.01:1
for q=0:0.01:1-p
for r=0:0.01:1-p-q
[ua,ub]=BNE(p,q,r);
E(i)=ua+ub;
x(i)=p;
y(i)=q;
z(i)=r;
i=i+1;
end
end
end
[X,Y,Z]=meshgrid(x,y,z);
surf(X,Y,Z,E)
But it failed. How plot the data (x,y,z,E). Where BNE() is the self-defining function.

Answers (1)

Keita Abe
Keita Abe on 12 Oct 2022
I found that two points for reconsindering
  • meshgrid function requires unique array of x, y, z.
  • surf function requires the surface definition but your input is volume data
If you would like to know the isosurface, I hope the following code would be helpful. Or if you would like to define the surface, the following link will be helpful. 2 次元または 3 次元の散布データの内挿 - MATLAB griddata - MathWorks 日本
i=1;
for p=0:0.01:1
for q=0:0.01:1-p
for r=0:0.01:1-p-q
[ua,ub]=BNE(p,q,r);
E(i)=ua+ub;
x(i)=p;
y(i)=q;
z(i)=r;
i=i+1;
end
end
end
[X,Y,Z]=meshgrid(unique(x),unique(y),unique(z));
vq = griddata(x,y,z,E,X,Y,Z);
isosurface(X,Y,Z,vq,0.5)
function [ua, ub] = BNE(p,q,r)
ua = p+q;
ub = q+r;
end

Categories

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

Community Treasure Hunt

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

Start Hunting!