複数のグラフィックスオブジェクトのプロパティを一括変更するには、どのようにすればよいですか?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 25 Okt. 2013
Beantwortet: MathWorks Support Team
am 25 Okt. 2013
下記のように、一度に2本のラインのプロパティを変更しようとすると、エラーが発生します。どのようにすればよいですか?
x = 0:pi/10:2*pi;
y = [sin(x);cos(x)];
h = plot(x,y);
set(h,'ydata',5*y)
(エラーメッセージ)
??? エラー: ==> set 値は列、または行ベクトルでなければなりません.
Akzeptierte Antwort
MathWorks Support Team
am 25 Okt. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu グラフィックス オブジェクトの識別 finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!