How to have a new line inside a string ?
Show older comments
set(handles.parameterW,'string',{['stiffness = ',num2str(A),' Nm/deg,',' Damping = ',num2str(B),' Nm/(rad/s)']});
Current output:
stiffness = 1 Nm/deg, Damping = 0 Nm/(rad/s)
Output i required:
stiffness = 1 Nm/deg,
Damping = 0 Nm/(rad/s)
3 Comments
Tayyab Khalil
on 20 May 2021
You can simply use the fprintf function i suppose:
fprintf('Stiffness = %d Nm/deg, \nDamping = %d Nm/(rad/s) \n', A, B)
Gives the desired output as you asked.
Vinothkumar Sethurasu
on 20 May 2021
Stephen23
on 20 May 2021
"But, i don't know, how to use inside set(handles.parameterW.....)"
Change FPRINTF to SPRINTF
Answers (3)
Girijashankar Sahoo
on 20 May 2021
set(handles.parameterW,'string',{['stiffness = ',num2str(A)+newline+' Nm/deg,',' Damping = ',num2str(B),'
or
set(handles.parameterW,'string',{['stiffness = ',num2str(A),\n' Nm/deg,',' Damping = ',num2str(B),'
1 Comment
Vinothkumar Sethurasu
on 20 May 2021
Chandra Amma Palanisamy
on 20 May 2021
Hi Vinothkumar,
It is my understanding that you want to insert a newline in a string. The example code is given below:
set(handles.parameterW,'string',{['stiffness = ',num2str(A),' Nm/deg,', newline,' Damping = ',num2str(B),' Nm/(rad/s)']});
Hope this helps.
1 Comment
Vinothkumar Sethurasu
on 20 May 2021
LeChat
on 19 Feb 2025
What about if we need to write a graph title over two lines?
With
title({'First line'},{'Second line'})
I managed to have two lines as "a title" but in fact the second line is not in bold, contrary to the first line.
Any idea?
1 Comment
Les Beckham
on 19 Feb 2025
Put both char vectors inside the same cell array like this
title({'First line', 'Second line'})
Categories
Find more on Lengths and Angles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!