xline issue with adding a number to the line through the labels option

조회 수: 12 (최근 30일)
Jason
Jason 2024년 6월 4일
댓글: Aditya 2024년 6월 4일
Is there a reason why the xline (or yline) functions won't accept a number converted to a string
c=b(3); %Breakpoint
cs=num2str(c)
class(cs)
xline(ax3,c,cs);
cs =
'125.7048'
ans =
'char'
Error using xline
Invalid parameter/value pair arguments.

채택된 답변

Aditya
Aditya 2024년 6월 4일
Hi Jason,
In MATLAB, the xline function is designed to add vertical lines to a plot and allows for customization through various parameters, including adding a label directly to the line. However, this customization needs to be done using 'Name,Value' pairs. When you attempt to pass the string representation of a number directly as an argument, without specifying it as part of a 'Name,Value' pair, MATLAB does not recognize it as a valid input, leading to the "Invalid parameter/value pair arguments" error.
To add a label to your line correctly, you need to use the 'Label' option followed by the string you wish to use as the label. Here's how you can adjust your code:
% Correct way to add Label
xline(ax3,c,'Label',cs);
I hope this clears up the confusion!
  댓글 수: 3
Jason
Jason 2024년 6월 4일
and to further add, reading again it says this:
To create a line with a label, you must also specify the line style. The default line style is a solid line, '-'.
x = linspace(0,6,100);
y = exp(x);
plot(x,y)
xline(4.5,'-',{'Acceptable','Limit'});
So it is possible without the 'Label' but you need to specify the line stsyle, so actually this worked also.
xline(ax3,c,'-',cs);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by