why do strings I define to same length have different lengths?
Show older comments
I am defining entries for a legend on a plot figure. Here's my code:
lg1 = sprintf('Widebeam MP Mean = %7.4g Var = %7.4g',mn1, vr1);
lg2 = sprintf('CPM 0 Mean = %7.4g Var = %7.4g',mn2, vr2);
lg3 = sprintf('Standard MP Mean = %7.4g Var = %7.4g',mn3, vr3);
lg4 = sprintf('Coarse Widebeam MP Mean = %7.4g Var = %7.4g',mn4, vr4);
When I examine the length of these strings, they are not always identical. But, more important to - for esoteric presentation [of results] reasons is that when I use legend() to display the array [lg1; lg2; lg3 lg4] the lines have different apparent lengths (more than the variance in length() lengths) and they don't line up vertically. lg2 is always the shortest - it has the most blank spaces. lg4 is always the longest. The numeric values of the mean are 0-3 digits; the values for variance can be 0-4 digits. BUT, these don't seem to be the issue (mean & variance length in digits). Rather, it's the size in pixels of the letters in the legend names.
Ultimately, I want the words 'Mean" and "Var" to align vertically. How can I force this to happen?
Accepted Answer
More Answers (0)
Categories
Find more on Legend 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!