複数のグラフィックスオブジェクトのプロパティを一括変更するには、どのようにすればよいですか?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 25 Oct 2013
Réponse apportée : MathWorks Support Team
le 25 Oct 2013
下記のように、一度に2本のラインのプロパティを変更しようとすると、エラーが発生します。どのようにすればよいですか?
x = 0:pi/10:2*pi;
y = [sin(x);cos(x)];
h = plot(x,y);
set(h,'ydata',5*y)
(エラーメッセージ)
??? エラー: ==> set 値は列、または行ベクトルでなければなりません.
Réponse acceptée
MathWorks Support Team
le 25 Oct 2013
setコマンドの第2,第3入力引数の"プロパティ名"と"設定値"を「セル配列」で与えます。
set(h,{'ydata'},num2cell(5*y,size(y)))
% set(h,{'ydata'},{5*y(1,:); 5*y(2,:)})と等価
上記の例は、同じ種類のグラフィックスオブジェクト(ラインオブジェクト)を変更していますが、異なる種類のオブジェクトに対しても、同様に変更することができます。
% 例) ラインオブジェクトとテキストオブジェクトのColorプロパティ変更
hL = plot(rand(1,10)); % ラインの色:青
hT = text(4,0.4,'テキスト'); % テキストの色:黒
set([hL;hT],{'Color'},{'r';'g'}) % ラインの色を赤、テキストの色を緑に変更
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur グラフィックス オブジェクトの識別 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!