MATLAB: Problem with refreshing linked plot data

datalinklinkdataMATLABplotrefreshrefreshdata

The code sample I have below links data to a plot, and then starts modifying the data. The problem is that the plot never refreshes during the for loop. The linked plot only refreshes after the program is done.
Calling refreshdata in the for loop is not an option, because it takes too long and breaks the flow of the program. Any ideas on what I could do/try? I need for the plot to update every few seconds without breaking program flow.
clear all
close all
t = [0];
y = [0];
figure
h = plot(t,y);
set(h,'XDataSource','t');
set(h,'YDataSource','y');
linkdata on
for i = 1:50
t(i) = i;
y(i) = sin(i)
% refreshdata
pause(.1)
end

Best Answer

clear all
close all
t = [0];
y = [0];
figure
h = plot(t,y);
for i = 1:50
t(i) = i;
y(i) = sin(i)
set(h, 'XData', t, 'YData', y);
pause(.1)
end