MATLAB Answers

Split legend after blank space

조회 수: 21(최근 30일)
JB
JB 11 Oct 2017
댓글: JB 11 Oct 2017
I know this has been discussed several times before, but I still cannot figure it out. I have a 4x1 cell with stings I want to use as plot legends, and it is working fine. The first 3 strings comes from a checkbox selection and string 4 comes from averaging plot 1-3.
Title = {
'123456789_1'
'ABCDEFGHIJ_1'
'123ABC_1'
'Av. (123456789_1 ABCDEFGHIJ_1 123ABC_1)'
}
Is it possible to devide string no 4 into multiple lines with a linebreak after each blank space so that string number 4 would be:
Av.
(123456789_1
ABCDEFGHIJ_1
123ABC_1)

  댓글 수: 0

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

채택된 답변

Guillaume
Guillaume 11 Oct 2017
Just use strrep to replace the spaces by a linefeed (char(10)):
legend(strrep(Title, ' ', char(10)));

  댓글 수: 1

JB
JB 11 Oct 2017
GREAT, thanks Guillaume

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

추가 답변(1개)

KL
KL 11 Oct 2017
leg_str = {'123456789_1'
'ABCDEFGHIJ_1'
'123ABC_1'};
leg_str{4,1} = ['Avg.' char(10) '(' leg_str{1,1} char(10) leg_str{2,1} char(10) leg_str{3,1} ')'];
plot(rand(10,4));
legend(leg_str)

  댓글 수: 0

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by