Matlab plot 4D data

6 ビュー (過去 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 Center および File ExchangeDiscrete Data Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by