How to define LineSpec in one variable?

Hello everyone,
I would like to specify the line properties in one variable. For example, the code
plot([1,2],[1,2],'Color','black','LineWidth',2);
should be replaced by a code of the form (which produces an error):
LineSpec = {'Color','black','LineWidth',2};
plot([1,2],[1,2],LineSpec);
Thanks for any help!
plot([1,2],[1,2],'Color','black','LineWidth',2);

 採用された回答

Walter Roberson
Walter Roberson 2020 年 12 月 7 日

1 投票

LineSpec = {'Color','black','LineWidth',2};
plot([1,2],[1,2],LineSpec{:});

1 件のコメント

Stephan
Stephan 2020 年 12 月 7 日
Great! Thank you very much!

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

その他の回答 (0 件)

カテゴリ

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

タグ

質問済み:

2020 年 12 月 7 日

コメント済み:

2020 年 12 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by