Repeating sequence in xlabel

조회 수: 2 (최근 30일)
Santos García Rosado
Santos García Rosado 2021년 4월 23일
댓글: Santos García Rosado 2021년 4월 23일
Hello,
I'm trying to repeat a sequence on the xlabel of the figure I've attached.
Since I'm plotting a vector that has 160 values, the xlabel goes from 1 to 160 as you can see on the figure. But I'd like the xlabel to display a sequence going from 1 to 20 8 times. (8*20 = 160). This is the code I'm using to plot the figure
plot((1:(numel(InputVect))),InputVect*100, 'linewidth', 2);
title('MyFig', 'FontName', 'Cambria', 'FontSize', 13);
xlabel('X', 'FontName', 'Cambria','FontSize', 13);
ylabel('Y', 'FontName', 'Cambria','FontSize', 13);
I've been trying to work around a way using set(gca,'xticklabel',) but I haven't managed a result so far.
Could someone please help me out?
Thank you,
Santos

채택된 답변

Chunru
Chunru 2021년 4월 23일
a = gca;
a.XTick = (1:160); % (0:5:160)
a.XTickLabel = string(mod(0:159, 20)+1); % mod(0:5:160, 20)
This repeats the label 1:20 for 8 times. However, there are two many labels to show and you may want to adjust the interval. For example, you can try the values in the comments above.
  댓글 수: 1
Santos García Rosado
Santos García Rosado 2021년 4월 23일
Thank you @Chunru. You're right, there are way to many labels to show. I'll try different values and see which fit better. Thank's!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by