Axis Ticks using Calendar Year ticks with BC years

조회 수: 1 (최근 30일)
Charles Mina
Charles Mina 2023년 1월 23일
댓글: Walter Roberson 2023년 1월 24일
I have some code here used for Grain Size analysis of a core, I wanted to correlate each point with an age, so I created a list with age of each with years and formatted them to use the 'yyyy G' format. however when I try to use the yticks command to create certain tick labels, it says that it cannot use the list since it is not "increasing" due to how the ISO labelling system works for years. is there a way to make this work? Code without and with system is below.
cla reset
plot(GSListNorm,DepthList)
set(gca,'YDir','reverse')
yyaxis left
xline(median(GSListNorm),"--r")
xlabel(["Normalized Grain Size at 90%"])
ylabel(["Depth";"(cm)"])
xlim([-2 5])
ylim([0 110])
yticks(0:10:max(DepthList))
yyaxis right
plot(GSListNorm,YearAge,LineStyle='none')
ylabel(["Age","Calendar Year"])
ytickformat('yyyy G')
saveas(gcf,'GSNoTrend','png')
cla reset
YearTicks = datetime('1950' '1725' '1501' '1277' '1053' '0828' '0604' '0380' '0156' '0069' '0293')% I know this code isn't right but these are the values of the list
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

Error in connector.internal.fevalMatlab

Error in connector.internal.fevalJSON
cla reset
plot(GSListNorm,DepthList)
set(gca,'YDir','reverse')
yyaxis left
xline(median(GSListNorm),"--r")
xlabel(["Normalized Grain Size at 90%"])
ylabel(["Depth";"(cm)"])
xlim([-2 5])
ylim([0 110])
yticks(0:10:max(DepthList))
yyaxis right
plot(GSListNorm,YearAge,LineStyle='none')
ylabel(["Age","Calendar Year"])
ytickformat('yyyy G')
yticks(YearTicks)
saveas(gcf,'GSNoTrend','png')
cla reset
Error using yticks
Tick values must be a vector of increasing datetime values.

채택된 답변

Walter Roberson
Walter Roberson 2023년 1월 23일
이동: Walter Roberson 2023년 1월 23일
YearTicks = datetime({'1950 CE'; '1725 CE'; '1501 CE'; '1277 CE'; '1053 CE'; '0828 CE'; '0604 CE'; '0380 CE'; '0156 CE'; '0069 CE'; '0293 BCE'}, 'Inputformat', 'yyyy G', 'Format', 'yyyy G');
plot(rand(1,length(YearTicks)), YearTicks)
yticks( sort(YearTicks))
  댓글 수: 2
Charles Mina
Charles Mina 2023년 1월 24일
Thank You! but i would like to ask why the sort is necessary?
Walter Roberson
Walter Roberson 2023년 1월 24일
yticks() requires that the values be given in increasing order, but your input YearTicks are in decreasing order.
You could also have done
yticks( flipud(YearTicks) )
but that is fragile against the possibility that YearTicks is already increasing, or against the possibility that YearTicks is a row vector instead of a column vector.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by