Thursday, December 19, 2013

Maksud perintah eval di MATLAB

Berikut ini saya berikan contoh penggunaan perintah eval di MATLAB. Silakan dites di komputer anda... kebetulan saya g bisa buat video demonya lantaran koneksi lambat :D.
sayang = ['clc;',... 
'f = figure;', ... 
'x = linspace(-pi,pi,100 );', ... 
'y = sin(x);',... 
'maju = 1;',... 
'm = 1;',...
'n = 1;',... 
'while ishandle(f)',...
    'for i=1:length(x)',... 
        'p = plot(x(1:i),y(1:i), ''linewidth'', 3);'...
        'hold on;'...
        'p1 = plot(x(i), y(i),''r.'' , ''markersize'', 30);'...
        'axis([-pi pi -1 1]);'...
        'pause(0.01);',...
        'if ishandle(p), delete(p); end,'...
        'if ishandle(p1),delete(p1); end,'...
    'end,',...
    'for i=length(x):-1:1',...
    'p = plot(x(i:length(x)),y((i:length(y))), ''linewidth'', 3);',...
     'p1 = plot(x(i), y(i),''r.'' , ''markersize'', 30);'...
     'axis([-pi pi -1 1]);'...
        'pause(0.01);',...
        'if ishandle(p), delete(p); end,',...
         'if ishandle(p1),delete(p1); end,'...
    'end,',...
'end'];
eval(sayang);

No comments: