Error using fsurf (too many functions) but success using ezsurf

조회 수: 10 (최근 30일)
When using the fsurf command to plot this function, I recieve the message: "error using fsurf, too many functions."
By simply changing "fsurf" to "ezsurf" I successfully get my 4 figures (intended to model tumors).
I understand there is a difference in the plotting methods of fsurf and ezsurf, and I assume that fsurf, if correctly used, would give me more detailed figures. What could be causing the discrepancy? I appreciate any and all help!
syms u v
for a = 3:4
for b = 5:6
figure
fsurf((1+1/5*sin(a*u)*sin(b*v))*sin(v)*cos(u),(1+1/5*sin(a*u)*sin(b*v))*sin(v)*sin(u),(1+1/5*sin(a*u)*sin(b*v))*cos(v),[0 2*pi 0 pi])
end
end

채택된 답변

madhan ravi
madhan ravi 2019년 11월 22일
편집: madhan ravi 2019년 11월 22일
Just vectorize the function and use function handles. To learn the proper usage of the functions that get you into a dilemma is to read the documentation page of the function.
fsurf(@(u,v)(1+1/5*sin(a*u).*sin(b*v)).*sin(v).*cos(u),(1+1/5*sin(a*u).*sin(b*v)).*sin(v).*sin(u),(1+1/5*sin(a*u).*sin(b*v)).*cos(v),[0 2*pi 0 pi]) % just alter your line to this line
doc fsurf % to open the documentation of the function
However I'm not getting the same error message that you're getting and it's not familiar.
  댓글 수: 2
Austin Vander Linden
Austin Vander Linden 2019년 11월 22일
I appreciate the help, however I'm still getting the same error.
Austin Vander Linden
Austin Vander Linden 2019년 11월 22일
Update- I opened a fresh instance of matlab and the command works perfectly. I'm unsure what was causing the error message, but I'm fine now. Thank you !

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

추가 답변 (1개)

Balu
Balu 2023년 1월 5일
Convert your interval argument to a double
fsurf(f, double(plot_range))
MATLAB doesn't always evaluate the final values of expressions. For example, you used 2*pi in your code. This has to be evaluated to 6.28. But if MATLAB finds it suitable, it can decide to just leave it as 2*pi and evaluate later when needed. But when your expressions are not evaluated, I think your plot range is considered a vector function. By doing double(plot_range), you get a scalar array, which is what fsurf needs.
  댓글 수: 4
Balu
Balu 2023년 1월 7일
편집: Balu 2023년 1월 7일
@WalterRoberson I'd expect that to be the case for any programming language, but it doesn't appear that MATLAB is rigorous enough to do that.
When I have a range matrix of unevaluated expressions, I find that the double function is necessary to avoid the too many functions error from fsurf.
>> plot_range
[-pi/20, (11*pi)/20, -5, 5]
>> f
f =
sin(x)^20
>> fsurf(f, plot_range)
Error using fsurf
Too many functions.
>> fsurf(f, double(plot_range))
>>
MATLAB version: 9.13.0.2145394 (R2022b) Update 3
Walter Roberson
Walter Roberson 2023년 1월 7일
Ah, what is going on there is that you have defined your plot_range symbolically (you are getting symbolic π there), and your f is symbolic as well. Your fsurf(f,plot_range) is then passing two symbolic expressions to fsurf(), which is only expecting one symbolic expression. The range does need to be numeric (not symbolic) for fsurf(). But this has nothing to do with "vector function" or "scalar array".

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

카테고리

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

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by