필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Lauren Miller
Lauren Miller 2021년 4월 29일
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