필터 지우기
필터 지우기

I got an errow while plotting 3D surface

조회 수: 1 (최근 30일)
Yellow Canary
Yellow Canary 2015년 1월 16일
댓글: Yellow Canary 2015년 1월 18일
Imported the data from excel and the below are my vectors.
Pa 267751x1 2142008 double
Pb 267751x1 2142008 double
Profit 267751x1 2142008 double
When I type surf(Pa,Pb,Profit), I got this error message: Z must be a matrix, not a scalar or vector.
Anyone knows how can I fix this?
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2015년 1월 17일
Sercan - please describe your data and why you are attempting to plot it all as a 3D surface? The error message is pretty clear on the problem - the third input Profit must be a matrix. Given your dimensions from above, and according to surf, the third input must be a 267751x267751 matrix.
Yellow Canary
Yellow Canary 2015년 1월 18일
Pa and Pb are probabilities of different events that affect my profit function. My profit function has 8 variables. At first I assume 4 of them are constant. I run a 4 for loops for the rest of the variables and got a table that includes all the combinations. Now, I want to see the profit change for different Pa and Pb values. I keep other 2 variables constant as well. I want to plot Pa on x, Pb on y and Profit on z axis.
Thank you.

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

채택된 답변

Roger Stafford
Roger Stafford 2015년 1월 18일
If I understand you correctly, the matlab 'surf' function is not the right one for your problem, since it would require that your 'Profit' variable be a two-dimensional matrix. I think the best you can do is to use 'plot3' with the "LineSpec" argument set to produce point displays, not lines between points:
plot3(Pa,Pb,Profit,'.')
This will give you a single dot for each triplet of corresponding values of Pa, Pb, and Profit.
It will be a little more difficult to interpret than a plot by 'surf' because the lines connecting neighboring dots are not plotted, but unfortunately your data is not in a form that would allow this to be done conveniently. To see why this is so, read the documentation for 'surf'. At one point it states: "The height, Z, [the third argument] is a single-valued function defined over a geometrically rectangular grid." It is this grid nature of the input that allows 'surf' to draw the connecting lines, and which is missing in your data.
  댓글 수: 2
Star Strider
Star Strider 2015년 1월 18일
I usually prefer stem3 for discrete 3D plots, because it directly connects the x, y, and z values for each triplet. However, since there are 2E+6 data triplets, that might be a less attractive option here.
Yellow Canary
Yellow Canary 2015년 1월 18일
Thank you

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by