How can I change multiple fields in a nested structure?

3 ビュー (過去 30 日間)
Jesse
Jesse 2015 年 10 月 28 日
コメント済み: Jesse 2015 年 10 月 28 日
I am trying to change the color of plots in a graph through the figure handle. The figure handle is part of a structure of figure handles. Each plot has a marker and a line and the Color property of each marker and line is nested in the structure as follows
plot 1 line color for Figure n: h(n).Children.Children(1).Color
plot 1 marker color for Figure n: h(n).Children.Children(2).Color
plot 2 line color for Figure n: h(n).Children.Children(3).Color
plot 2 marker color for Figure n: h(n).Children.Children(4).Color
etc.
For a given Figure n, I would like to set the Color property for both the marker and line for a plot at once, e.g. I would like to change the color of plot 1 by assigning a single value to h(n).Children.Children(1:2).Color.
Here is my attempt with setfield
h = setfield(h,{12},'Children',{1},'Children',{1:2},'Color',[1 0 0])
But this gives me this error: Error using setfield (line 56) Insufficient number of outputs from function on right hand side of equal sign to satisfy overloaded assignment.

採用された回答

Kelly Kearney
Kelly Kearney 2015 年 10 月 28 日
You should be able to do this via set:
set(h(n).Children.Children(1:2), 'Color', [1 0 0]);
  1 件のコメント
Jesse
Jesse 2015 年 10 月 28 日
That did it. Thanks very much.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by