Matlab plot 4D data

4 次查看(过去 30 天)
Yi Liu
Yi Liu 2022-10-12
回答: Keita Abe 2022-10-12
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.

回答(1 个)

Keita Abe
Keita Abe 2022-10-12
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

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by