Domanda

I am facing a strange behavior on Matlab. I want to plot a simple surface in 3D with a variable parameter.

Simple example :

param = 0.5;
[x,y]=meshgrid(linspace(-1,1,10),linspace(-1,1,10));
z = param*x./y;
surf(x,y,z);

I get a classic 3D picture : http://i.imgur.com/2KrnWeH.png

I am now trying to add a slider on my figure to directly control the value of parameter :

function test()
    figHandle=figure;
    param = 0.5;
    [x,y]=meshgrid(linspace(-1,1,10),linspace(-1,1,10));
    z = param*x./y;
    surfacePlotted = surf(x,y,z);

    sliderPosition=[10 400 200 20];

    hsl = uicontrol('Style','slider','Min',-2,'Max',2,'SliderStep',[1 1]./(10),'Value',param,'Position',sliderPosition,'Callback',{@updatePlot,surfacePlotted});
end

function updatePlot(hObject,~,eventdata)
    surfacePlotted=eventdata;
    param = get(hObject,'Value');
    x=get(surfacePlotted,'XData');
    y=get(surfacePlotted,'YData');
    z = param*x./y;
    set(surfacePlotted,'ZData',z);
end

I get a nice slider, and I can click on it to modify the parameter : http://i.imgur.com/TqkMSmH.png i.imgur.com/i9xablF.png (second picture with an other position for the slide

However the main menu bar is not here anymore, especially the "Pan" icon which allow me to manipulate in 3D the figure.

I tried to add it manually after my slider definition

uicontrol('MenuBar','figure');

and I also tried :

set(figHandle, 'MenuBar', 'figure');

without success so far.

Anyone already encoutered this issue and found a work around ? Or Am I simply missing something easy ?

Thanks :)

Edit : Edited picture links, I put the one to manage them

È stato utile?

Soluzione

It is addressed here in Yair's website (undocumentedmatlab):

uicontrol side-effect: removing figure toolbar

You only need to add this line into your code:

set(figHandle,'toolbar','figure');
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top