Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your colorbars are children of the figure, not of your subplot axes (colorbars are themselves axes). Try</p> <pre><code>hc = get(hf, 'children') </code></pre> <p>to get a list of all children of the figure, where <code>hf</code> is the figure handle. I'm not sure how you would which element of <code>hc</code> is equal to your <code>Hc</code>, i.e. which is the <code>first</code> colorbar.</p> <p><strong>Edit</strong>:</p> <p><strong>If you need to use an object's handle later on, it is best to assign it to a variable when it is created and to use that variable throughout.</strong></p> <p>However, if you don't want to do this (although I strongly recommend that you do) I can think of two things you can do. They are not particularly elegant and are definitely more work that just assigning your object handle to a variable.</p> <p>If you know the order in which the axes were created then you are in luck: in the list if children, the first child created is the <em>last</em> element in the list and the last child created is the <em>first</em>. For example,</p> <pre><code>hf = figure; ha1 = subplot(1,2,1); image(rand(5,5)); hc1 = colorbar; ha2 = subplot(1,2,2); image(rand(5,5)); hc2 = colorbar; hcs = get(hf, 'children') hcs = 206.0016 204.0011 176.0016 174.0011 [hc2, ha2, hc1, ha1]' ans = 206.0016 204.0011 176.0016 174.0011 </code></pre> <p>Since you want the first colorbar, which was the second child created, you can then use</p> <pre><code>hc(end-2) </code></pre> <p>Alternatively, when creating the colorbar which you want to refer to in the future, set it's <code>tag</code> property. In the above example, replace the line</p> <pre><code>hc1 = colorbar; </code></pre> <p>with</p> <pre><code>hc1 = colorbar('tag', 'myID'); </code></pre> <p>You can then get the handle to this object later with</p> <pre><code>findobj(hf, 'type', 'axes', 'tag', 'myID') </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload