Im getting a blank graph, and alot of errors.

x = inline ('t>0', 't');
t1 = -2;
t2 = 6;
t = [t1, t2];
fplot (x, t)
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments.
Error using string
Conversion to string from inline is not possible.

Error in matlab.graphics.function.mixin.Legendable/displayNames (line 36)
s.none = replace(string(fn),[".*" ".^" "./"],["*" "^" "/"]);

Error in matlab.graphics.function.FunctionLine/updateFunction

Error in matlab.graphics.function.FunctionLine/set.Function_I

Error in matlab.graphics.function.FunctionLine/set.Function

Error in matlab.graphics.function.FunctionLine

Error in fplot>singleFplot (line 245)
hObj = matlab.graphics.function.FunctionLine(fn{1},extraOpts{:},args{:});

Error in fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 200)
hObj = cellfun(@(f) singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);

Error in fplot>vectorizeFplot (line 200)
hObj = cellfun(@(f) singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);

Error in fplot (line 166)
hObj = vectorizeFplot(cax,fn,limits,extraOpts,args);

 Risposta accettata

Use an anonymous function instead of the deprecated inline function, and since the ‘x’ function actually returns a logical result, convert it to a numerical result by performing an arithmetic operation on it, here being a unary plus —
x = @(t) +t>0;
t1 = -2;
t2 = 6;
t = [t1, t2];
fplot (x, t)
xlabel('t')
ylabel('x')
... and the plot of the function magically appears!
.

Più risposte (0)

Categorie

Prodotti

Release

R2022b

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by