How to add different texts in xline, when using arrayfun ?

How to add different texts in xline, when using arrayfun, as in the following example?
% Input and current status
fig = figure();
ax = axes(fig);
ax.XTick = 1:14;
hold on
arrayfun(@(x)xline(x,'-','S','LabelOrientation','horizontal','Color',[.5 .5 .5]), 0:13)
% Desired Output:

2 件のコメント

Antoni Garcia-Herreros
Antoni Garcia-Herreros 2023 年 3 月 17 日
Hello Sim,
You could try something like this for each case:
a(3).Label='M';a(3).Color='k'; % Maybe change FontName and FontSize
Although I'm sure there must be a better way of doing it.
I cannot find a way to have different color for the text and the lines.
Sim
Sim 2023 年 3 月 17 日
Thanks a lot @Antoni Garcia-Herreros... :-) Actually, I was looking for a little bit "more automatic" way to do so... :-)

サインインしてコメントする。

 採用された回答

Star Strider
Star Strider 2023 年 3 月 17 日

1 投票

Perhaps something like this —
fig = figure();
ax = axes(fig);
ax.XTick = 1:14;
dy = ["S","S","M","T","W","T","F"];
hxl = xline(ax.XTick-1,'-k',repmat(dy,1,fix(max(ax.XTick)/7)), 'LabelOrientation','horiz');
.

4 件のコメント

Sim
Sim 2023 年 3 月 17 日
Super trick! Many thanks @Star Strider!!! :-)
Star Strider
Star Strider 2023 年 3 月 17 日
As always, my pleasure!
The only caution is that the x-ticks must be in integer multiples of 7, otherwise that code will break, and a slightly different approach will be necessary.
.
Sim
Sim 2023 年 3 月 17 日
編集済み: Sim 2023 年 3 月 17 日
ah ok cool! Again many thanks :-)
.....Also..... just in case you want to get another "Accepted Answer" ..........there would be also this small thing here........ :-) :-)
Star Strider
Star Strider 2023 年 3 月 17 日
Thank you for the reference!
I posted an Answer to it.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeWord games についてさらに検索

質問済み:

Sim
2023 年 3 月 17 日

コメント済み:

2023 年 3 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by