How to wrap text in title - app designer

35 views (last 30 days)
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

Answers (1)

Mohammed Sadiq
Mohammed Sadiq on 15 Jun 2021
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 Comment
Kartikeya Singh-Freeman
Kartikeya Singh-Freeman on 7 Oct 2021
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?

Sign in to comment.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!