How do I correct meridian labels exceeding 180 degrees with the Mapping Toolbox?
2 views (last 30 days)
Show older comments
MathWorks Support Team
on 20 May 2021
Answered: MathWorks Support Team
on 23 Jun 2021
When labeling meridians in the mapping toolbox, my axis reads [200W 180W 160W] instead of [160E 180W 160W]. How do I correct this?
Accepted Answer
MathWorks Support Team
on 20 May 2021
Use the "wrapTo360" function to change the angle corresponding to each label between 0 to 360 degrees. Additionally, check if the angle turns out to be greater than 180 degrees. If so, do a string replacement to change the label from 'W' to 'E'.
This code will simply need to be pasted at the end of your current code:
h = mlabel('on');
for i=1:length(h)
labelStrings(i)=string(h(i).String{2});
value = str2double(extractBetween(labelStrings(i),2,"^"));
value = wrapTo360(value);
if value > 180
value = 360 - value;
labelStrings(i) = strcat(" ",num2str(value),"^{\circ} E");
h(i).String{2} = labelStrings(i);
end
end
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!