Defining a simple function with text/string 'on'

The Idea I'm thinking about really is simple and actually just for getting used to 'functions'
My Code is just based on:
ax = gca
ax.GridColor = [1, 1, 1];
set(ax,'color','k')
I can actually copy it in any script wher plots are included for getting a dark background. But it just strikes me as it would be easier for such things to have a simple command like grid on
So maybe you see where I am getting at: I want a function like
darkmode('Color',[1,1,1])
or simply
darkmode on
as short-cut for the code above.
It's not a huge reduction, but I could actually draw a lot of the mechanism.

2 件のコメント

Stephen23
Stephen23 2021 年 5 月 18 日
@Niklas Kurz: what is your question?
Niklas Kurz
Niklas Kurz 2021 年 5 月 20 日
was fairly answered.

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

 採用された回答

David Hill
David Hill 2021 年 5 月 18 日

0 投票

function darkmode(a)
gca;
if a
ans.GridColor = [1, 1, 1];
set(ans,'color','k');
else
ans.GridColor = [.15,.15,.15];
set(ans,'color','w');
end

1 件のコメント

Stephen23
Stephen23 2021 年 5 月 21 日
It is not considered good MATLAB practice to rely on ans like that. Better to obtain the output explicitly:
function darkmode(a)
axh = gca;
if a
axh.GridColor = [1, 1, 1];
set(axh,'color','k');
else
axh.GridColor = [.15,.15,.15];
set(axh,'color','w');
end

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

2021 年 5 月 18 日

コメント済み:

2021 年 5 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by