Suppose I have set a parameter
a=2; b=1;
I want to display these information on a different window (like a plot window). Please advise.

 채택된 답변

Star Strider
Star Strider 2018년 4월 22일

0 개 추천

Try this:

a=2; b=1;
figure(1)
plot((1:10), rand(1,10), 'p')
grid
ps = {'a' 'b'};                                             % Define Parameter Names
pv = [2 1];                                                 % Define Parameter Values
for k = 1:numel(pv)
    cstr{k} = sprintf('%s = %.2f', ps{k}, pv(k));           % Cell Array
end
text(7, 0.7, cstr)                                          % Text Output In Plot

댓글 수: 2

alpedhuez
alpedhuez 2018년 4월 22일
Not that complicated. Let me work on it.

The loop is necessary because there are two different classes of variables (a char and a double) in the sprintf statement.

I could have created ‘pv’ as:

pv = [a b];                                                 % Define Parameter Values

since they were defined previously.

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Graphics Objects에 대해 자세히 알아보기

제품

태그

질문:

2018년 4월 22일

댓글:

2018년 4월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by