[Scilab-users] Refresh plot from Slider

Antoine Monmayrant antoine.monmayrant at laas.fr
Mon Sep 8 10:20:26 CEST 2014


On 09/07/2014 08:58 AM, Tan Chin Luh wrote:
> Hi,
>
> first of all, the handles to the sliders are wrong, you were using the 
> text handles instead of the sliders handles in both pushbutton and 
> slider callback.
>
> secondly you need to be careful on the sampling, with 0.01, u could 
> only plot sine wave
> with < 50 Hz. (nyquist)
>
> finally remember to delete the previous plot before redrawing. infact 
> it is not the best way to delete and plot and redraw it everytime 
> especially you want to use the slider to plot the graph, be ready for 
> a lagging effect.
The fastest option is to modify the data in the plot (and re-zoom if 
needed) instead of deleting/replotting.

Antoine
>
> hope this helps.
>
> rgds,
> CL
>
> On 07-Sep-14 12:32 PM, tanthiamhuat wrote:
>> referring to the below weblink
>> http://www.equalis.com/blogpost/731635/Scilab-Tips?tag=guibuilder+graphic+user+interface 
>>
>>
>> How do we refresh the plot with the slider? I try to put in the code 
>> for the
>> Plot button, but it does not work.
>> see code below, thanks.
>>
>> // This GUI file is generated by guibuilder version 2.2
>> //////////
>> f=figure('figure_position',[375,60],'figure_size',[656,604],'auto_resize','on','background',[33],'figure_name','Graphic 
>>
>> window number %d');
>> //////////
>> delmenu(f.figure_id,gettext('File'))
>> delmenu(f.figure_id,gettext('?'))
>> delmenu(f.figure_id,gettext('Tools'))
>> toolbar(f.figure_id,'off')
>> handles.dummy = 0;
>> handles.sliderAmp=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','helvetica','FontSize',[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[20],'Min',[0],'Position',[0.0932716,0.8253968,0.23,0.0335714],'Relief','flat','SliderStep',[10,10],'String','1','Style','slider','Value',[10],'VerticalAlignment','middle','Visible','on','Tag','sliderAmp','Callback','sliderAmp_callback(handles)') 
>>
>> handles.sliderFreq=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','helvetica','FontSize',[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[100],'Min',[0],'Position',[0.0932716,0.7097502,0.23,0.0335714],'Relief','flat','SliderStep',[20,20],'String','1','Style','slider','Value',[50],'VerticalAlignment','middle','Visible','on','Tag','sliderFreq','Callback','sliderFreq_callback(handles)') 
>>
>> handles.Amp=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','helvetica','FontSize',[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[100],'Min',[0],'Position',[0.1548765,0.7891473,0.0964815,0.0324031],'Relief','flat','SliderStep',[0.01,0.1],'String','Amplitude','Style','text','Value',[20],'VerticalAlignment','middle','Visible','on','Tag','Amp','Callback','sliderAmp_callback(handles)') 
>>
>> handles.Freq=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','helvetica','FontSize',[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[100],'Min',[0],'Position',[0.1551235,0.6595349,0.1083951,0.0339535],'Relief','flat','SliderStep',[0.01,0.1],'String','Frequency','Style','text','Value',[1],'VerticalAlignment','middle','Visible','on','Tag','Freq','Callback','') 
>>
>> handles.pbPlot=uicontrol(f,'unit','normalized','BackgroundColor',[0.6,0.6,0.6],'Enable','on','FontAngle','normal','FontName','helvetica','FontSize',[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.0932716,0.4604651,0.0952469,0.0403876],'Relief','raised','SliderStep',[0.01,0.1],'String','Plot','Style','pushbutton','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','pbPlot','Callback','pbPlot_callback(handles)') 
>>
>> handles.Axes1= newaxes();handles.Axes1.margins = [ 0 0 0
>> 0];handles.Axes1.axes_bounds = 
>> [0.3503086,0.0503876,0.5895062,0.5949612];
>> handles.editTime=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','helvetica','FontSize',[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.0932716,0.5829279,0.2114198,0.0447471],'Relief','sunken','SliderStep',[0.01,0.1],'String','0:0.01:10','Style','edit','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','editTime','Callback','') 
>>
>>
>>
>> //////////
>> // Callbacks are defined as below. Please do not delete the comments 
>> as it
>> will be used in coming version
>> //////////
>>
>> function sliderAmp_callback(handles)
>> //Write your callback for  slide1  here
>> funcprot(0)
>> amp = get(handles.Amp,'value');
>> frq = get(handles.Freq,'value');
>> t= evstr(get(handles.editTime,'String'));
>> y=amp.*sin(2*%pi*frq.*t);
>> plot(t,y);
>> endfunction
>>
>>
>> function sliderFreq_callback(handles)
>> //Write your callback for  sliderFreq  here
>>
>> endfunction
>>
>>
>> function pbPlot_callback(handles)
>> //Write your callback for  pbPlot  here
>> funcprot(0)
>> amp = get(handles.Amp,'value');
>> frq = get(handles.Freq,'value');
>> t= evstr(get(handles.editTime,'String'));
>> y=amp.*sin(2*%pi*frq.*t);
>> //if ~isempty(handles.Axes1.children)
>> //    delete(handles.Axes1.children)
>> //end
>> plot(t,y); xgrid();
>> endfunction
>>
>>
>>
>>
>>
>>
>> -- 
>> View this message in context: 
>> http://mailinglists.scilab.org/Refresh-plot-from-Slider-tp4031131.html
>> Sent from the Scilab users - Mailing Lists Archives mailing list 
>> archive at Nabble.com.
>> _______________________________________________
>> users mailing list
>> users at lists.scilab.org
>> http://lists.scilab.org/mailman/listinfo/users
>>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>





More information about the users mailing list