I'm trying to have a plot with a constant line at value y=39. I'm using function fplot() with a constant double as argument. This works for any value (e.g. fplot(38), fplot(40)) except for fplot(39). Anyone has an idea or ad alternative way to get a constant line plot on y=39. Thanks A
The error message while running fplot(39) is the following Error using symvar>isquoted (line 154) Quotes in S are not in pairs.
Error in symvar (line 49) q = isquoted(s);
Error in countvars>symvarMulti (line 17) vars = reshape(symvar(c),1,[]);
Error in countvars>symvarMulti (line 10) vars = cellfun(@symvarMulti, c, 'UniformOutput', false);
Error in countvars (line 5) n = numel(symvarMulti(outer));
Error in fplot>singleFplot (line 225) nvars = countvars(fn);
Error in fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 193) hObj = cellfun(@(f) singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);
Error in fplot>vectorizeFplot (line 193) hObj = cellfun(@(f) singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);
Error in fplot (line 163) hObj = vectorizeFplot(cax,fn,limits,extraOpts,args);

 채택된 답변

Star Strider
Star Strider 2018년 11월 3일

1 개 추천

The fplot function is interpreting ‘39’ as a single quote, its ASCII equivalent:
chr39 = char(39)
chr39 =
'''
Using an anonymous function plots the lines:
fplot(@(x)39+x-x)
The strange appearance avoids several lines of warning messages that would otherwise result.

댓글 수: 5

Alessandro Tufano
Alessandro Tufano 2018년 11월 3일
Thank you, it does work!
John D'Errico
John D'Errico 2018년 11월 3일
Just an addendum to Stars answer:
If you want to plot a constant line at some value, you can also use refline. Thus,
plot(rand(1,100),'o')
% now a constant line, at y == 0.75, slope == 0
hold on
refline(0,0.75)
Star Strider
Star Strider 2018년 11월 3일
As always, my pleasure!
I may submit an ‘enhancement request’ to MathWorks to see if they are interested in ‘trapping’ fplot to avoid this problem.
Steven Lord
Steven Lord 2018년 11월 3일
An addendum to John's addendum: if you're using release R2018b or later you can use yline. yline is in MATLAB, while refline is in Statistics and Machine Learning Toolbox.
madhan ravi
madhan ravi 2018년 11월 4일
편집: madhan ravi 2018년 11월 4일
An addendum to Steven's addendum:
fplot(subs(sym('y'),39)) %does the same
NOTE:
fplot(subs(sym('x'),39)) %won't plot a vertical line
the above will work the same that's why I made a FEX for this purpose

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2018년 11월 3일

편집:

2018년 11월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by