複数のグラフィックスオブジェクトのプロパティを一括変更するには、どのようにすればよいですか?
4 views (last 30 days)
Show older comments
MathWorks Support Team
on 25 Oct 2013
Answered: MathWorks Support Team
on 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 値は列、または行ベクトルでなければなりません.
Accepted Answer
MathWorks Support Team
on 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 Comments
More Answers (0)
See Also
Categories
Find more on グラフィックス オブジェクトの識別 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!