Truncating elements of Vector for XTick and YTick
Mostra commenti meno recenti
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
Risposte (3)
Michael Haderlein
il 23 Lug 2014
0 voti
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
il 23 Lug 2014
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
il 23 Lug 2014
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.
Categorie
Scopri di più su Axis Labels in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!