Problem with using 'DisplayName' property in fplot()

Hello everbody,
I wrote a function to plot a limit value in a existing figure. You can see it below. This function works well without using 'DisplayName' in fplot().
If I want to use 'DisplayName' I have got the following error:
Error using plot
Error in color/linetype argument.
Error in fplot (line 154)
plot(xx,y,marker,'parent',cax)
Error in limits (line 48)
fplot(f, axes.XLim, 'DisplayName', 'Test')
Can someone help me to fix this problem.
Thank you in advance,
Lennart
function limits(fig, standard)
%% Code
axes = fig.CurrentAxes;
axes.NextPlot = 'add';
if strcmp(standard, 'ECE R10 10m QuasiPeak')
f1 = @(x) 32;
f2 = @(x) 32 + 15.13 .* log10(x/75000000);
f3 = @(x) 43;
elseif strcmp(standard, 'ECE R10 10m Average')
f1 = @(x) 22;
f2 = @(x) 22 + 15.13 .* log10(x/75000000);
f3 = @(x) 33;
elseif strcmp(standard, 'ECE R10 3m QuasiPeak')
f1 = @(x) 42;
f2 = @(x) 42 + 15.13 .* log10(x/75000000) ;
f3 = @(x) 53;
elseif strcmp(standard, 'ECE R10 3m Average')
f1 = @(x) 32;
f2 = @(x) 32 + 15.13 .* log10(x/75000000) ;
f3 = @(x) 43;
elseif strcmp(standard, 'ECE R10 EUB QuasiPeak')
f1 = @(x) 62 - 25.13 .* log10(x/3000000);
f2 = @(x) 52 + 15.13 .* log10(x/75000000) ;
f3 = @(x) 63;
elseif strcmp(standard, 'ECE R10 EUB Average')
f1 = @(x) 52 - 25.13 .* log10(x/3000000);
f2 = @(x) 42 + 15.13 .* log10(x/75000000) ;
f3 = @(x) 53;
else
error('Dies ist kein vorhandener Grenzwert!')
end
f = @(x) f1(x).*((30000000 <= x) & (x <= 75000000)) + f2(x).*((75000000 < x) & (x < 400000000)) + f3(x).*((400000000 <= x) & (x < 1000000000));
fplot(f, axes.XLim, 'DisplayName', 'Test')
end

댓글 수: 2

Problem seems not to be "DisplayName" property but the limits given by axes.XLim.
Kind regards,
Robert
But without axes.XLim I have got the same error.

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

답변 (1개)

madhan ravi
madhan ravi 2020년 7월 23일
편집: madhan ravi 2020년 7월 23일

0 개 추천

F = fplot(f);
set(F, 'DisplayName', 'Test')

댓글 수: 8

Right. DisplayName is not an option that is accepted by fplot(). fplot() only accepts some color related and marker related and line style related options, together with some mesh options.
If I'm using it like you I have got the error:
Index exceeds matrix dimensions.
Error in fplot (line 56)
lims = args{2};
Error in limits (line 47)
F = fplot(f);
If I'm using it with axes.XLim():
F = fplot(f, axes.XLim);
set(F, 'DisplayName', 'Test');
I have got the error:
Error using matlab.graphics.Graphics/set
There is no DisplayName property on the Root class.
Error in limits (line 48)
set(F, 'DisplayName', 'Test');
which fplot -all % ?
Hope you didn’t mess the stock file.
@madhan ravi: I have got this as response:
C:\Program Files\MATLAB\R2015b\toolbox\matlab\specgraph\fplot.m
So I think this is right or?
@walter roberson: But why I can find it FunctionLine Properties. Besides they use 'LineWidth' in an example of the fplot function. This will give the same error.
Ah, notice they are using R2015b.
In R2015b,
[X,Y] = fplot(FUN,LIMS,...) returns X and Y such that Y = FUN(X). No plot is drawn on the screen.
So you have to do something like
curchild = get(axes,'Children');
fplot(f, axes.XLim);
newchild = get(axes, 'Children');
newline = setdiff(newchild, curchild);
set(newline, 'DisplayName', 'Test')
and at some point
legend show
Thank you sir Walter!
Yeah this works fine. Thank you Walter.

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

카테고리

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

제품

릴리스

R2015b

질문:

2020년 7월 23일

댓글:

2020년 7월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by