How to wrap text in title - app designer
45 ビュー (過去 30 日間)
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 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,' ');
current = indices(i);
old_title(current) = our_delimiter;
prev = current;
new_title = split(old_title, our_delimiter);