How can I save data when it is being generated in a loop?
古いコメントを表示
Hi, I am trying to generate a real time simulation of a sine wave and its derivative. The problem I am facing now is trying to save the data of the sine wave and its derivative while its being generated in the while loop to another file type, for exapmle Excel. So I am trying to save each iteration in excel while its running the data. I am really not sure if this possible or not to do so in Matlab.
You can find the code below. Please ask if you need any clearfication and any help is highly appriciated. Thank you in advance.
a = 5;
w = 0.2;
ts = 0.1;
t = -ts;
y = 1;
i = 1;
while t <= 40
t = t + ts;
y = a * sin(2*pi*w*t);
y1(i) = y;
T(i) = t;
if i == 1
b(i) = a*sin(2*pi*w*(t-ts));
x1 = (y1(i) - b(i))/ts;
else
x1 = ( y1(i) - y1(i - 1) )/ts;
end
x(i) = x1;
i = i + 1;
j = i - 1;
plot(T(1:j),y1(1:j),'b','linewidth',1);
hold on;
plot(T(1:j),x(1:j),'r','linewidth',1);
xlim([0 40]);
ylim([-7 7]);
grid on;
grid minor;
pause(0.01);
end
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!