How to define LineSpec in one variable?

48 vues (au cours des 30 derniers jours)
Stephan
Stephan le 7 Déc 2020
Commenté : Stephan le 7 Déc 2020
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);

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Déc 2020
LineSpec = {'Color','black','LineWidth',2};
plot([1,2],[1,2],LineSpec{:});
  1 commentaire
Stephan
Stephan le 7 Déc 2020
Great! Thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by