Plotting a function with 2 dependent variables

조회 수: 59 (최근 30일)
Abinav
Abinav 2021년 1월 7일
댓글: Star Strider 2021년 1월 7일
Hi,
I have a function a variable (z) which is dependent on two other variables (x,y). The function looks like z = f(x,y)
x ranges from 0 to 100 and y ranges from 0 to 1. I use linspace to divide both x and y into 100 values.Through nested loop substitution, I get 100 x 100 values for z.
How do I plot z against x and y? If I use plot3 I get an error saying dimensions don't match.
Thanks

채택된 답변

Star Strider
Star Strider 2021년 1월 7일
Use the mesh or surf functions. Other options are contour, and waterfall, depending on the result you want.
  댓글 수: 2
Abinav
Abinav 2021년 1월 7일
Contour is what I was looking for.
Thanks.
Star Strider
Star Strider 2021년 1월 7일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mischa Kim
Mischa Kim 2021년 1월 7일
Use meshgrid instead:
[x,y] = meshgrid(-10:0.1:10);
z = sin(x).*cos(y);
plot3(x,y,z)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by