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);

 Akzeptierte Antwort

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!
.

2 Kommentare

John
John am 10 Mär. 2023
Thank you so much!
Star Strider
Star Strider am 10 Mär. 2023
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Function Creation finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2022b

Tags

Gefragt:

am 10 Mär. 2023

Kommentiert:

am 10 Mär. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by