how to avoid the newline in figure annotation, please help. I give the example code below.

rng=10;
f1=50;
figure
annotation('textbox',[0.0202708333333333 0.328350515463918 0.220875 0.579278350515467],'String',{'3D distance = ',rng,'2D distance = ',f1});

 Accepted Answer

Using cell string, each cell will be in a new line. Change the cell string to char array as follows:
rng=10;
f1=50;
figure
plot(rand(10,1))
annotation('textbox',[0.0202708333333333 0.328350515463918 0.220875 0.579278350515467],...
'String',sprintf('3D distance = %.0f \n 2D distance = %.0f', rng, f1),...
'FitBoxToText','on', 'EdgeColor',[1 1 1],'Interpreter','latex');

3 Comments

Thank you very much. it solved my problem. but the text is not aligned?the rest is ok, but the text is not aligned as shown in the figure.
annotation('textbox',[0.0202708333333333 0.328350515463918 0.220875 0.579278350515467],'String',sprintf('3D-distance = %f \n 2Ddistance = %f \n AOD = %f \n ZOD = %f \n AOA = %f \n ZOD = %f \n Sector = %.0f', rng, f1, AOD(iter), ZOD(iter), AOA(iter), ZOA(iter), sec(iter) ),'FitBoxToText','on', 'EdgeColor',[1 1 1],'FontSize', 22,'Interpreter','latex');
Remove the space after \n in the sprintf command.

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!