Truncating elements of Vector for XTick and YTick

I have a figure containing 30 subplots. I need to be able to set my x and y tick labels. I know how to set them, but my values have 6 decimal places, which matlab won't even try to use as labels in such a crowded figure. The increment by .02,so I only need 2 decimal places to fit the criteria of montonically increasing values for xtick and yick. I tried rounding each element like:
roundEl=round(origEl*100)/100;
but this just gives me 14.16000 or whatever the value is. I really need to get rid of those zeros, or find a way to move my subplots further apart, but the latter seems more difficult to do within the loops that i create my images in.
So are there any other truncating tips that i don't know?
thanks

답변 (3개)

Michael Haderlein
Michael Haderlein 2014년 7월 23일

0 개 추천

That's almost the same question as this one:
I'm not sure if that's the most elegant way, but I don't know another and nobody else replied.
Best regards,
Michael
Kelly Kearney
Kelly Kearney 2014년 7월 23일
Not quite sure I understand the issue... the format of tick values when your print them to screen has no relation to how they are displayed in the tick labels themselves.
If you want to manually set the tick locations:
xlim = get(gca, 'xlim');
xtick = round(xlim(1)*100)/100:0.02:xlim(2);
set(gca, 'xtick', xtick);
If you want to explicitly specify the format of the labels:
set(gca, 'xticklabel', cellstr(num2str(xtick', '%.2f')));
Star Strider
Star Strider 2014년 7월 23일
The way I usually do it is inelegant but effective. In your application it might go something like this:
for k1 = 1:length(origEl)
xtklbl{k1} = sprintf('%.2f', origEl(k1));
end
then use those as your XTickLabel array values. Do something similar for YTickLabel. There may be more efficient ways, but this works.

카테고리

도움말 센터File Exchange에서 Axis Labels에 대해 자세히 알아보기

질문:

2014년 7월 23일

답변:

2014년 7월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by