How can I save the output in a loop to an external text file?

2 次查看(过去 30 天)
For my final project, I am measuring how the eccentricity of an orbit changes based on external forces introduced to the system
In my loop, I'm trying to save the outputted values of eccentricity to a text file so that I can use this to plot the answers for my results but it's just not working and I have no clue where I'm going wrong.
I don't want to save every value that comes out because there'll be a lot, I just want to save 1 value for every 100 so I've set up a for loop but I'm not very experienced with MATLAB so I think it's ended up a bit of a mess. Any help would be incredibly appreciated
The loop:
D=dot(P(2,:), V(2,:))
e1=norm(V(2,:));
e1=e1^2
mu=G*M(1)
e2=e1/mu
r1=norm(P(2,:))
e3=e2/r1
e4=e3*P(2,:)
e5=D/mu
e6=e5*V(2,:)
e=e4-e6
emag=norm(e)
emag=emag/1.0e+10
t = t + steps*delta;
update_plot(P,H,t)
m = 0;
m = m + 1;
if m == 100;
i = 1:n
C{i} = emag;
C2{i} = t;
E(i,1) = emag;
E(i,2) = t;
dlmwrite('local filename.txt',emag,'-append', '\t')
dlmwrite('local filename.txt',t,'-append', '\t')
m = 0;
end
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by