How to plot a function with 3 independent variables

f(x,y,z)=0.95*x+0.73*y+0.62*z-130.05
f(x,y,z); x; y; and z are values between 0 and 100.
f(x,y,z) is shown in color. How can I plot in MATLAB similar to figure below.
Thank you!

1 件のコメント

Walter Roberson
Walter Roberson 2021 年 10 月 13 日
slice()
Or possibly isosurface() called several times

サインインしてコメントする。

 採用された回答

KSSV
KSSV 2021 年 10 月 13 日

0 投票

f = @(x,y,z) 0.95*x+0.73*y+0.62*z-130.05 ;
x = linspace(0,100) ;
y = linspace(0,100) ;
z = linspace(0,100) ;
[X,Y,Z] = meshgrid(x,y,z) ;
V = f(X,Y,Z) ;
isosurface(X,Y,Z,V,1e-4)

6 件のコメント

Seng Hkawn N-Sang
Seng Hkawn N-Sang 2021 年 10 月 13 日
Thank you! This is really helpful. It does not work when the min and max for the variables are set to 60 and 100 and the upper and lower bounds for the V=f(x,y,z) are set to 70 and 100. How can I correct it?
I already have excel values for x,y,z, and f(x,y,z) in 4 columns where x in 1st column, y in 2nd, z in 3rd, and f(x,y,z) in 4th. How can I use excel data to plot in a similar plot in MATLAB?
Walter Roberson
Walter Roberson 2021 年 10 月 14 日
編集済み: Walter Roberson 2021 年 10 月 14 日
No values as small as 1e-4 in the subset of the data.
f = @(x,y,z) 0.95*x+0.73*y+0.62*z-130.05 ;
x = linspace(60,100) ;
y = linspace(60,100) ;
z = linspace(60,100) ;
[X,Y,Z] = meshgrid(x,y,z) ;
V = f(X,Y,Z) ;
Vmin = min(V(:))
Vmin = 7.9500
Vmax = max(V(:))
Vmax = 99.9500
levels = 10:10:100;
Nlevels = length(levels);
for K = 1 : length(levels)
isosurface(X, Y, Z, V, levels(K));
end
xlim auto; ylim auto; zlim auto
view(3)
legend(string(levels))
Seng Hkawn N-Sang
Seng Hkawn N-Sang 2021 年 10 月 14 日
Thank you so much! Almost there!!!
Can you please let me know how I can add contour lines (at PCI=70,75,80,85,90,95,& 100)?
KSSV
KSSV 2021 年 10 月 14 日
Replace levels with your required values.
Walter Roberson
Walter Roberson 2021 年 10 月 14 日
f = @(x,y,z) 0.95*x+0.73*y+0.62*z-130.05 ;
x = linspace(60,100) ;
y = linspace(60,100) ;
z = linspace(60,100) ;
[X,Y,Z] = meshgrid(x,y,z) ;
V = f(X,Y,Z) ;
Vmin = min(V(:))
Vmin = 7.9500
Vmax = max(V(:))
Vmax = 99.9500
levels = 70:5:100;
Nlevels = length(levels);
cmap = hot(Nlevels);
for K = 1 : Nlevels
s = isosurface(X, Y, Z, V, levels(K));
p(K) = patch(s);
p(K).EdgeColor = 'none';
p(K).FaceColor = cmap(K,:);
isonormals(X, Y, Z, V, p(K));
end
camlight;
lighting gouraud;
xlim auto; ylim auto; zlim auto
view(3); view(36, 64);
legend(p, string(levels))
You cannot do contour lines because you are dealing with a 3D object: you can only do ISO surfaces.
It might be possible to get the colors right without some of the above steps. With the default steps I showed in https://www.mathworks.com/matlabcentral/answers/1562461-how-to-plot-a-function-with-3-independent-variables#comment_1783116 you might notice that the colors come out wrong compared to the legend: it turns out that you are looking at the "back" of the plates, and that you need to view() to see the front (or you need to move the light.)
Seng Hkawn N-Sang
Seng Hkawn N-Sang 2021 年 10 月 15 日
Thank you both!
Got it working!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

製品

リリース

R2021b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by