Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7047457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:46:26+00:00 2026-05-28T02:46:26+00:00

Take the follow code for example: Hsp=subplot(1,2,1); image(rand(5,5)); Hc=colorbar; subplot(1,2,2); image(rand(5,6)); colorbar; My question

  • 0

Take the follow code for example:

Hsp=subplot(1,2,1);

image(rand(5,5));

Hc=colorbar;

subplot(1,2,2);

image(rand(5,6));

colorbar;

My question is how to obtain Hc, given only Hsp.

As is known, the type of a colorbar is axes. So I tried to search all the children of the subplot.

Hs=findall(Hsp,'type','axes');

But, there is no value in Hs which matches Hc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:46:27+00:00Added an answer on May 28, 2026 at 2:46 am

    Your colorbars are children of the figure, not of your subplot axes (colorbars are themselves axes). Try

    hc = get(hf, 'children')
    

    to get a list of all children of the figure, where hf is the figure handle. I’m not sure how you would which element of hc is equal to your Hc, i.e. which is the first colorbar.

    Edit:

    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.

    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.

    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 last element in the list and the last child created is the first. For example,

    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
    

    Since you want the first colorbar, which was the second child created, you can then use

    hc(end-2)
    

    Alternatively, when creating the colorbar which you want to refer to in the future, set it’s tag property. In the above example, replace the line

    hc1 = colorbar;
    

    with

    hc1 = colorbar('tag', 'myID');
    

    You can then get the handle to this object later with

    findobj(hf, 'type', 'axes', 'tag', 'myID')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow-up question to this one . Take a look at these
Take this code: <?php if (isset($_POST['action']) && !empty($_POST['action'])) { $action = $_POST['action']; } if
Take the following two lines of code: for (int i = 0; i <
Take the following string as an example: The quick brown fox Right now the
Take the following generics example import java.util.List; import java.util.ArrayList; public class GenericsTest { private
My question (which will follow after this, sorry about the long intro, the question
I'm supposed to write this c++ that take in 01 and on. for example:
Take the following example, class Cup {} class MyObject { protected $cups = array();
A question regarding everything runs in parallel except your code from someone new to
Let's take as an example 3 entities being page (a webpage), a link and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.