overlap ylabel with values axis

조회 수: 4 (최근 30일)
mattvanviore
mattvanviore 2022년 3월 10일
답변: AndresVar 2022년 3월 10일
i have this problem both for x axis anz y axis, how can i solve?
another question: how can i convert input data to character? Sometimes i use the option x='1.2e7' but i would to generalize and use it both for legend and write a new file. I have tried to use num2str but the number 1.2e7 becomes 12000000

답변 (2개)

Walter Roberson
Walter Roberson 2022년 3월 10일
format long g
x = 1.2e7
x =
12000000
num2str(x, '%.1e')
ans = '1.2e+07'
sprintf('%.1e', x)
ans = '1.2e+07'
compose('%.1e', x)
ans = 1×1 cell array
{'1.2e+07'}
num2str() invokes sprintf() internally (except for integers, if I recall -- I think it calls int2str() for those.)
compose() can be useful for outputing arrays; sprintf() is a nuisance for outputing arrays of different types.
However... if you need to be able to distinguish between x = 12.e6 and x=1.2e7 and automatically output exactly the same way that it was input, then you are going to need to input as character (or string) and str2double() when you need the numeric form.
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 3월 10일
If you ask to retrieve the YLabel property of the axes, then you will get back a text() object. text() objects have a Position property, which you can change to move the place the text is placed.

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


AndresVar
AndresVar 2022년 3월 10일
many ways to modify the label position: modify position property, if in latex add \quad, etc
the easy way is to control the horizontal alignment
a = (1:3)/10
a = 1×3
0.1000 0.2000 0.3000
figure;
plot(a);
yl=ylabel('aaaaaaaaaaaa','Rotation',0);
figure;
plot(a);
yl=ylabel('aaaaaaaaaaaa','Rotation',0,'HorizontalAlignment','right');

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by