Command findobj('T​ype','Func​tionLine') produces error if used after fplot invoked with three arguments, fplot(X,Y,LIMITS) - 0×0 empty GraphicsPlaceholder array

조회 수: 1 (최근 30일)
I am preparing a short test in MATLAB Grader, but I am struggling with one particular feature. Namely, I can't seem to assess the validity of a symbolic function plot, using the commands assert, fplot(X,Y,LIMITS) and findobj.
Here is an example code derived from MathWorks samples. If I run
clear variables
syms x y real
figure;
f(x) = sin(x)/x;
fplot(x,f,[-4*pi,4*pi])
legend show
lineobj = findobj('Type','FunctionLine')
I get error message lineobj =
0×0 empty GraphicsPlaceholder array.
If one changes the last line with the following (losing X argument)
fplot(f,[-4*pi,4*pi])
then it works.
Is there a way to introduce flexibility so that the student can use both variants of the fplot?

채택된 답변

Stephen23
Stephen23 2024년 11월 28일
편집: Stephen23 2024년 11월 28일
A curve defined by a function of X and a function of Y is a parametric curve, so you would need to search for the corresponding object type 'ParameterizedFunctionLine' :
syms x y real
f(x) = sin(x)/x;
fplot(x,f,[-4*pi,4*pi])
lineobj = findobj('Type','ParameterizedFunctionLine')
lineobj =
ParameterizedFunctionLine with properties: XFunction: x YFunction: [1x1 symfun] TRange: [-12.5664 12.5664] Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 Use GET to show all properties
You could thus search for both line objects and check which one is empty/scalar/whatever size.
Also note that FPLOT does return the line objects as outputs.

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by