Hi
I have 3 vectors, where:
X is a vector of numbers;
Y is a vector of numbers;
Z is a function that depends on X and Y (i.e)
Z = 4.6597*x.^2 + 2.6897*x.*y - 0.023578*x + 8.1189*y.^2 - 1.9553*y - 1.2304;
I want to plot a 3D curve and I am not succeding. Can someone help me please? Thanks

 採用された回答

Star Strider
Star Strider 2021 年 4 月 23 日
編集済み: Star Strider 2021 年 4 月 23 日

1 投票

Use the plot3 function.
If you then want it as a 2D plot, use the view function to rotate it.
EDIT — (23 Apr 2021 at 03:17)
I was intending that to use any of the q3D plotting functions, the vectors need to be transformed into matrices first, and then transformed back into vector to use plot3:
X = ...;
Y = ...;
[Xm,Ym] = ndgrid(X,Y);
Zfcn = @(x,y) 4.6597*x.^2 + 2.6897*x.*y - 0.023578*x + 8.1189*y.^2 - 1.9553*y - 1.2304;
Zm = Zfcn(Xm,Ym);
figure
plot3(Xm(:), Ym(:), Zm(:))
grid on
.

8 件のコメント

Bryan Ambrósio
Bryan Ambrósio 2021 年 4 月 23 日
Great man, thank you so much.
Star Strider
Star Strider 2021 年 4 月 23 日
編集済み: Star Strider 2021 年 4 月 23 日
My pleasure!
Bryan Ambrósio
Bryan Ambrósio 2021 年 4 月 23 日
編集済み: Bryan Ambrósio 2021 年 4 月 23 日
I am also trying to use
contour(Xm, Ym, Zm), it worked just fine
But i want to be sure if the Z axis is beeing cutted in points 1, 2, 3, ..., 8.
How can i make sure of that?
And i think it will be better if in figure of contour the ordened pair appears only as a 'x' or 'o', and not the entire line
Star Strider
Star Strider 2021 年 4 月 23 日
If you want to specify those contours:
contour(Xm, Ym, Zm, (1:8))
The extra parentheses are not strictly necessay, I added them for clarification.
X = ...;
Y = ...;
[Xm,Ym] = ndgrid(X,Y);
Zfcn = @(x,y) 4.6597*x.^2 + 2.6897*x.*y - 0.023578*x + 8.1189*y.^2 - 1.9553*y - 1.2304;
Zm = Zfcn(Xm,Ym);
figure
contour(Xm, Ym, Zm, (1:8))
axis('equal')
If you want to label the contours:
contour(Xm, Ym, Zm, (1:8), 'ShowText','on')
That worked when I tried it with my own set of vectors.
Bryan Ambrósio
Bryan Ambrósio 2021 年 4 月 30 日
編集済み: Bryan Ambrósio 2021 年 4 月 30 日
Hi, im sorry to bother you again, but now i need to make the same plots, but:
X, Y and Z are vector (not function anymore), how do i do that?
I have tried:
X = ...;
Y = ...;
Z = ...;
[Xm,Ym, Zm] = ndgrid(X,Y,Z);
figure
contour(Xm, Ym, Zm, (1:8))
axis('equal')
but its not working
Star Strider
Star Strider 2021 年 4 月 30 日
No worries!
Do this instead —
X = ...;
Y = ...;
Z = ...;
xv = linspace(min(X),max(X),numel(X));
yv = linspace(min(Y),max(Y),numel(Y));
[Xm,Ym] = ndgrid(xv,yv);
Zm = griddata(X,Y,Z,Xm,Ym);
figure
contour(Xm, Ym, Zm, (1:8))
axis('equal')
That should work.
.
Bryan Ambrósio
Bryan Ambrósio 2021 年 4 月 30 日
Thank you so much!
Star Strider
Star Strider 2021 年 5 月 1 日
As always, my pleasure!

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

その他の回答 (2 件)

Bryan Ambrósio
Bryan Ambrósio 2021 年 4 月 23 日

0 投票

I have tried plot3, but it doesnt fill my needs entirely
Bryan Ambrósio
Bryan Ambrósio 2021 年 4 月 23 日

0 投票

in plot3 z cannot be a function

カテゴリ

ヘルプ センター および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

製品

リリース

R2018a

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by