How to wrap text in title - app designer

31 ビュー (過去 30 日間)
David Mabwa
David Mabwa 2021 年 5 月 2 日
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
Kartikeya Singh-Freeman 2021 年 10 月 7 日
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?

サインインしてコメントする。

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by