# How can I multiply axis values by 1000 without changing the data?

조회 수: 179 (최근 30일)
onamaewa 2019년 4월 11일
댓글: Nawfal Al-Zubaidi 2023년 6월 5일
With the script shown below,
figure()
for CH = 2:33
Y = (avg(:,CH) - avgBG(CH) + SP);
hold on
plot(avg(:,1), Y)
xlim([0 0.3]); xlabel('Time (s)');
ylim([-0.034 0.034]); ylabel('Position (m)');
SP = SP + 2/1000;
end
I've created this figure:
I want to change the Y-axis values on the figure to be multiplied by 1000.
I tried Yticks, but I don't think I've implemented it correctly. Any suggestions?

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

### 답변 (2개)

Rik 2019년 4월 11일
You can either multiply the y-values with 1000, or use the YTickLabels:
ticks=get(gca,'YTicks');%retrieve current ticks
ticks=ticks*1000;%multiply
ticks=cellfun(@num2str,tick,'UniformOutput',false);%convert to cellstr
set(gca,'YTickLabels',ticks)%set new tick labels
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Rik 2019년 4월 16일
Did this suggestion solve your problem? If so, please consider marking it as accepted answer. It will make it easier for other people with the same question to find an answer. If this didn't solve your question, please comment with what problems you are still having.

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

Rob Lander 2021년 1월 29일
편집: Rob Lander 2021년 1월 29일
Here's another approach that seems to work (shown here for the case where you wish to change the labels for three axes):
ax = gca;
tick_scale_factor = 1000;
ax.XTickLabel = ax.XTick * tick_scale_factor;
ax.YTickLabel = ax.YTick * tick_scale_factor;
ax.ZTickLabel = ax.ZTick * tick_scale_factor;
A problem with this approach is that if you resize the figure this can cause the number of tick labels to change, which, in turn, will lead to incorrect label values. The only work-around that I know of to solve this problem is to re-exectute the code above after re-sizing.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Nawfal Al-Zubaidi 2023년 6월 5일
Perfect, this worked for me. Thank you!
Nawfal AZR-Smith

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

### 카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by