MATLAB: How to make the colorbar in a self-programmed GUI stay at the same level (especially in the YDir) as the original image after adding axes’ labels

colorbarmatlab guiposition gui

Below is a code snippet that I have for a GUI I am creating, is there a way of accessing the colorbar so that I can perhaps make its position stay the same as opposed to changing when I resize the window? I tried using the axs{} as the parent but that did not work and I am still struggling with playing around with OuterPosition, ActivePositionProperty and Position because of a possible 'Units' mix-up. Thanks 😀
axs{9} = axes('Units','characters','Position', [0.87*(scr2(1)+scr2(3)) 0.38*(scr2(2)+scr2(4)) 0.11*scr2(3) 0.54*scr2(4)],'XColor', [1 1 1]);
lev_nf = linspace(30,90,50);
lev_bb = linspace(30,90,50);
for nf_idx = 1:length(lev_nf)
for bb_idx = 1:length(lev_bb)
noiselvl(nf_idx, bb_idx) = ((((lev_nf(nf_idx)-120)+90.6)*-.185 + ((lev_bb(bb_idx)-120)+90.6)*-.25)+8)*-.125;
end
end
noiselvl = max(noiselvl,-1);
noiselvl = min(noiselvl,2);
imagesc(lev_nf, lev_bb, noiselvl);
c = colorbar('location','eastoutside'); colormap hot
set(c,'HitTest','off'); % Make legend unclickable / unmoveable
set(axs{9},'YDir','normal');
xlabel('NoiseFloor MF')
ylabel('BB level')
set(axs{9},'XColor',[0.7 0.7 1.0]);
set(axs{9},'YColor',[0.7 0.7 1.0]);
hold on
lh_nfl = plot(30,30,'g*','MarkerSize',10);
rh_nfl = plot(30,30,'k*','MarkerSize',10);

Best Answer

What if you set set() to set the Position property of the colorbar handle
set(c, 'Position', [left, top, width, height]);