MATLAB Answers

Translated by

이 페이지의 내용은 영어에서 자동 번역되었습니다. 자동 번역 기능을 해제하려면 "<a class="turn_off_mt" href="#">여기</a>"를 클릭하십시오.

0

How to fix the ticklabels - time series analysis?

Asked by Nadezhda Dimitrova on 27 Apr 2019
Latest activity Commented on by dpb
on 5 May 2019
Accepted Answer by dpb
Hello,
I have a question with regard to the xlables when plotting timeseries.
It is a timeseries analysis with about 5000 observations (t) and 20 constituencies (N).
I would like to have on the x-axis the labels of t/N instead of the number of the data point. Therefore, I calculated C = t/N and tried to use it as a xticklabels but it does not really work:
--> which is clearly not (1:5000)/20
Here is the code:
%% Calculating the concentration ratio C = t/N
for i = 1 : size(Data200018,1) % size = 4579
concentrationRatio(:,i) = i./NumberAssets; % NumberAssets = 20
end
%%Plot
figure;
plot(AE,'b-')
hold on
plot(AEDK,'r-')
ylabel('Average error','FontSize',12)
xlabel('Concentration Ratio','FontSize',12)
xticklabels(concentrationRatio)
hold off
I know that it is probably simpler than I think but I can’t figure it out :) Many thanks in advance for any advices!
Best,
Nadya

  0 Comments

Sign in to comment.

1 Answers

Answer by dpb
on 27 Apr 2019
Edited by dpb
on 27 Apr 2019
 Accepted Answer

Clearly, the ticklabels you wrote are (1:5000)/20. The first label is 0.05 --> 1/20, the second 0.10 --> 2/20, etc., etc., ...
Matlab did precisely what you asked it to... :)
The problem is the tick marks aren't every x value else't there would be 5,090 of them...you must label only the ticks; per the documentation tick labels are just a 1:1 mapping of the input ticklabel values to the tick locations; if there are more labels than ticks the rest are ignored; fewer and the array is used from the beginning as many times as needed. Since your axis has 10 intervals there are 11 ticks and you labeled them with the values [1:11]/20
Use
xticklabels(xticks/concentrationRatio)
instead to label the actual ticks at 1/20th tick value

  2 Comments

Thanks a lot for the great explanation, @dpb!
It worked but in different lines as the dimensions of xticks and concentrationRatio were different. Very helpful, thanks!
Oh...that was a cut 'n paste error...the divisor should have been/was intended to be the constant NumberAssets instead...

Sign in to comment.



Translated by