how to plot number in legend ?

조회 수: 1 (최근 30일)
tomer polsky
tomer polsky 2018년 4월 6일
댓글: Walter Roberson 2018년 5월 14일
he this is my code
for a=[ 1 3 5]
hold on;
disp('a')
H1=tf([ a],[3 4 ])
step(H1)
end
I want that in the plot it will be written the value of a of each line in the legend is it possible ?
  댓글 수: 2
dpb
dpb 2018년 4월 6일
Sure, just use num2str to write whatever text (if any) you want for each line label and pass to legend
tomer polsky
tomer polsky 2018년 4월 7일
편집: tomer polsky 2018년 4월 7일
hi thank you for your answer ,but what I meant that it will be like this :
but insted that it will be written in the legend manually it will be written outamtacly

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

채택된 답변

Walter Roberson
Walter Roberson 2018년 4월 7일
avals = [ 1 3 5];
for a = avals
hold on;
disp(a)
H1 = tf([ a],[3 4 ])
step(H1)
end
legend( sprintfc('%g', avals) )
I think that your legend() call in your image has the wrong order. The larger the numerator in the transfer function, the more gain there should be, so the last a drawn, the 5, should be the last legend entry, but you have reversed the order.
  댓글 수: 1
tomer polsky
tomer polsky 2018년 4월 15일
thank you very much for your help !!! bless you

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

추가 답변 (1개)

tomer polsky
tomer polsky 2018년 5월 13일
Hi I have other question , how can I write "K=1" and not only "1" ?
  댓글 수: 6
dpb
dpb 2018년 5월 14일
편집: dpb 2018년 5월 14일
Hmmm....didn't notice but presumed tf something else as at least here
>> for a=[ 1 3 5]
hold on;
disp('a')
H1=tf([ a],[3 4 ])
step(H1)
end
a
Undefined function 'tf' for input arguments of type 'double'.
>>
the xfr-function requires a digital filter object for input, not a double so OP may have something else of same name or older release or...???
>> which tf -all
C:\ML_R2017\toolbox\signal\signal\@dfilt\tf.m % dfilt method
>>
Must admit haven't used it ever, though, since like R12 or thereabouts as gave up the consulting gig way back when so need went away...oldest release still at hand is R2014b and it's same need.
So, to OP--what is tf and what does step do to it??? I can't run what you have here to 'spearmint with--
Walter Roberson
Walter Roberson 2018년 5월 14일
>> which tf(1)
/Applications/MATLAB_R2018a.app/toolbox/control/ctrlmodels/@tf/tf.m % tf constructor
tf() is one of the primary routines for building transfer functions for control systems. step() with no output causes plotting of the transfer function.

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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by