How to make an object current in GUI matlab?
<p>I build a function "sng_figureslide" which spawns a slider that can slide through all figures that are already created. I have to click on de slider to be able to control it with the arrow keys.</p>

<p>I'm wondering if it is possible to make the slider-object active when I call the function so i don't have to click on the slider in advance.</p>

<pre><code>function sng_figureslide

figh=findobj('type','figure');
figs=numel(figh);

% if there are one or zero figures, the slider does not appear
if figs &gt; 1
    sliderstep = 1/(figs-1);
else
    return
end

fignumber = cell2mat(get(figh,'Number'));
sliderfignumber = max(fignumber) + 1;
figure(max(fignumber) +1)
set(gcf,'position',[360 190 560 36]);
set(gcf,'Toolbar','none');
a=annotation('textbox',[0.03 0.2 0.1 0.7],'String',num2str(figs));

uicontrol('Style', 'slider',...
    'Min',1,'Max',figs,'Value',figs,...  
    'Position', [80 10 470 20],...  
    'Callback', {@slider1,figh,a,figs,fignumber,sliderfignumber},...      
    'SliderStep', [sliderstep sliderstep]);
end

function slider1(hObj,~,figh,a,figs,fignumber,sliderfignumber)
    Val = round(get(hObj,'Value'));
    set(a,'String',num2str(Val));
    figure(figh(Val));
    figure(sliderfignumber);
end
</code></pre>

<p>Besides, i think this function is pretty useful for many people so feel free to use it.</p>