필터 지우기
필터 지우기

How to wrap text in title - app designer

조회 수: 28 (최근 30일)
David Mabwa
David Mabwa 2021년 5월 2일
댓글: Kartikeya Singh-Freeman 2021년 10월 7일
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