![]() ![]() Save the UI via menu: GUI Design -> Save UI.Ĭlear ( ) mode ( 0 ) lines ( 0 ) warning ( " off " ) // to turn off possible warnings due to long function names // sgd generated comment User-defined prefix code starts here do not modify this line and the ones above this global currentvalue global minvalue global maxvalue minvalue = 10 maxvalue = 100 currentvalue = 10 fig = figure ( " visible ", " off " ) // sgd generated comment User-defined prefix code ends here do not modify this line and the ones below this exec ( " C:\Users\user\Desktop\Example1\calculate_fft.sce ", - 1 ) exec ( " C:\Users\user\Desktop\Example1\form_FFTPlotter.scedesign ", - 1 ) // sgd generated comment User-defined postfix code starts here do not modify this line and the ones above this function = do_fft ( frequency ) x = sig = sin ( 2 * %pi * frequency * x ) = calculate_fft ( x, sig ) endfunction function updateFigure ( figHandle, x, y ) scf ( figHandle ) drawlater ( ) clf ( ) plot ( x, y ) //ax = gca() //ax.data_bounds = drawnow ( ) set ( fig, " visible ", " on " ) endfunction // sgd generated comment User-defined postfix code ends here do not modify this line and the ones below this Now you can verify that this code has indeed been associated with the callback function of the slider by checking the Callback code previewer tab in the Designer window. ![]() ![]() avoid bounce effects global currentvalue cvalue = get ( hslider3_FFTPlotter, " value " ) if ( cvalue currentvalue ) then currentvalue = cvalue set ( textfield2_FFTPlotter, " String ", sprintf ( " %d ", cvalue ) ) = do_fft ( cvalue ) updateFigure ( fig, f, abs ( fourier ) ) disp ( cvalue ) end The code can be saved either via pressing the " Update Callback Code" button or by pressing the key combination Ctrl S. callback_type = - 1 // switch off callback to Hence, one can type the following code in the Callback Editor: The task at hand is to redirect the "Value" property of the horizontal slider to a text field whose tag property is "textfield2_FFTPlotter". They can be easily discerned from the UI properties table. To set or get the values of of the various UI controls, one has to know their corresponding tags. This opens the Callback Editor what you type in this window appears between the two indicated comment lines in the callback function. Press the Edit Event Code button in the Scilab GUI Designer window. To modify the callback function of the horizontal slider, choose the slider (either via the UI Element drop-down list or via hovering the mouse over it). ![]() Scilab GUI Designer provides a convenient feature - it comes bundled with a callback event programming editor (or simply, Callback Editor), albeit without any bells and whistles such as code highlighting, code completion, intellisense, etc. One option would be to open the FFTPlotter_events.sce file, which contains the callback function, in an external editor and implement the code. To achieve this we have to modify the callback function of the horizontal slider and redirect its value to a text field (in our example, it is textfield2_FFTPlotter). And finally I have plotted the Fourier Series.One of the requirements for this UI program involves displaying the value of the horizontal slider's position in a text field. And in the previous post I had only calculated the Fourier Coefficients, a0, A, B, but this time I am using those to calculate the Fourier Series, through the function ‘solution’. Series=series A(i)*cos(i*%pi*x/l) B(i)*sin(i*%pi*x/l) Īs you can notice, the code is almost the same as before, except that I have changed the name of the function from ‘fourier’ to ‘fourierplot’. If you haven’t read the last post which is being continued here then I recommend you read that first here. I have used the same code as before and just added a few more lines of code. We can also use the Fourier Coefficients to calculate the Fourier Series and then Plot the FS Approximation and compare it to the original function. In the last post I showed you guys how to calculate Fourier Coefficients for a given function defined in the range. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |