I have an app which generates a png with plot and some text at the bottom. The plots are fine, but the text at the bottom the position is a problem . So i did this using uicontrol. One line of code in the app is
txt_title1 = uicontrol('Style', 'text', 'String',app.saveText1,'FontSize',10,'Position', pos1);
where app.saveText1 is the string pos1 is the position where it needs to be in the png. Right now, I made the mistake of hardcoding it. So how the program works is it creates a figure in the background without opening it to the user and saves the figure.
newFigure = figure ('visible','off');
saveas(newFigure,[FileName,'.png']);
This is how I did it. But to find the position of text what I do is remove the visible off and close figure, so that app opens displays the new figure. Then I click on edit plot, then use property inspector, then drag and adjust the text to how I want it, find the position in property inspector and use that position as pos1 hardcoded in the program and then bring back visible off and close figure and generate the program for the user. And when user runs the program and click save, a figure will be created in background and will be saved in the folder. And that figure will have the text in the correct position. But unfortunately the position of the string app.saveText1 is not fixed. It changes and when it changes the position in the png will also change. I have uploaded two pics below to show the problem, one with the corrected by me dragging and adjusting and second the wrong one.
You can see the difference in both. So from the property instructor i understood the position is [left bottom width height]. So I thought i can use string length to find the length of the string and use that for width for position. But apparently they are both different. For example in the picture above you can see Battery Data Path. The string length of that is 95 whereas in the position of that in property inspector when i corrected its 859. So instead of hard coding, I need to find a way for app to work this automatically using the string length and then work accordingly. How can I do that. Kindly do help me. Thank you.