How to wrap text in title - app designer

26 次查看(过去 30 天)
Hi there,
I have a gui that processes image files using multiple methods. This processing creates a string variable e.g.
title1 %(that is automatically generated based on method/s the user chooses and original image filename)
When the user selects multiple techniques, the file name becomes understanderbly long. When an image is plotted using imshow, and given this variable as its title, the title strays off screen or overlays adjacent axes titles when using tiledlayout. I was wondering if there was a way to wrap this text, so it automatically breaks into multiple lines based on the length of "title1" and the size of the axes.
I don't see how the normal method would work here (i.e. breaking the string manually) because the title is generated at a different section of the gui and only assigned to "title1" when the user decides to view the image.
Any help is appreciated.
Thanks in advance

回答(1 个)

Mohammed Sadiq
Mohammed Sadiq 2021-6-15
You can create a multiline title using a string array as shown in this answer. Break title into multiple lines? - MATLAB Answers - MATLAB Central (mathworks.com).
The title variable can be passed through the following function to generate multiline title string arrays of desired line lengths.
function new_title = wraptitle(old_title)
lineLen = 25; % Specify the minimum length of each line
our_delimiter = '$'; % Use a character that does not occur in the title
prev = 1;
indices = strfind(old_title,' ');
for i=1:length(indices)
current = indices(i);
if current>prev+lineLen
old_title(current) = our_delimiter;
prev = current;
end
end
new_title = split(old_title, our_delimiter);
end
  1 个评论
Kartikeya Singh-Freeman
Hey Mohammed,
I'm struggling to get this function working for a title that includes variables such as
XFactor = 1
old_title = "Transform of Image with X Factor of "+ XFactor +""
Are you able to provide some asistance on what changes to the function I need to make?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by