how to print
a = 0.1005:0.1:1.1005
as, 0.1, 0.2, 0.3, ... 1.0 for tickllabes?
I used sprintf command but the optput is not as expected.
ytl = sprintf('%.2f', 0.1005:0.1:1.1005);
ytl
0.100.200.300.400.500.600.700.800.901.001.10
How to give this as input to xticklabels?

 채택된 답변

Chunru
Chunru 2022년 8월 15일

0 개 추천

x = 0.1005:0.1:1.1005;
y = randn(size(x));
plot(x, y)
grid
% for x tick format
xtickformat('%.2f')
% Conversion of array to char array
ytl = sprintf('%.2f\n', 0.1005:0.1:1.1005)
ytl =
'0.10 0.20 0.30 0.40 0.50 0.60 0.70 0.80 0.90 1.00 1.10 '

댓글 수: 5

MP
MP 2022년 8월 15일
Actually X-values are
X = 1:11;
and instead of 1:11 i want to put 0.1005:0.1:1.1005 as xlabel.
So, could you please correct me.
However, this answer is also helpful, but not going to work in my case.
Chunru
Chunru 2022년 8월 15일
편집: Chunru 2022년 8월 15일
Not sure what you exactly mean. This is a guess:
x = 1:11;
y = randn(size(x));
plot(x, y);
xtick_pos = 1:11;
xtick_label = sprintf('%.2f\n', 0.1005:0.1:1.1005 );
xticks(xtick_pos);
xticklabels(xtick_label);
MP
MP 2022년 8월 15일
Yes, You got me right!
Now, how to get 0.10, 0.20, 0.30 etc as Xticklabels ?
Chunru
Chunru 2022년 8월 15일
편집: Chunru 2022년 8월 15일
See above for using sprintf. Beware that you may lose the precision of xtick label.
MP
MP 2022년 8월 15일
YES!!! magical...
That worked..
Thank you so very much...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

질문:

MP
2022년 8월 15일

댓글:

MP
2022년 8월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by