How to save part of the data in text file?

조회 수: 2 (최근 30일)
Jamie Al
Jamie Al 2021년 5월 7일
편집: Scott MacKenzie 2021년 5월 8일
I have the following plots at different time steps, I would like to save the data at the last time step in a text file. How can I simply do that?
For example my plotting section, I am saving the data into a multi-dimenional array that has the 3rd dim as t and would plot my data in three different timesteps. How can I save data in a text file at timestep 0.12 at the plots example and not the entire data.
Code:
t = 0;
step = 0;
hstep = 1;
wstep = 1;
while t < tend && step < N_max
[U_T, t] = MacCormack(U_T, gamma, t, dx, CFL, sigmma);
step = step + 1;
if mod(step,wstep) == 0
U_TData(:,:,hstep) = U_T; % How to save this data in text file?
Vp_Data(:,:,hstep) = C2P( U_T, gamma );
hstep = hstep+1;
t_Data(hstep) = t;
end
end
shiste = size(U_TData);
numframe = shiste(3);
iterframe = floor(numframe/3);
f1 = figure();
subplot(2,2,1)
for i = 1:3
plot(x,U_TData(1,:,i*iterframe))
hold on
Legend{i} = strcat('t=', num2str(t_Data(i*iterframe),'%.2f'));
end
Plots:

채택된 답변

Scott MacKenzie
Scott MacKenzie 2021년 5월 8일
편집: Scott MacKenzie 2021년 5월 8일
If you want to save the data being plotted on the last iteration (i = 3), try adding one line after your loop:
for i = 1:3
plot(x,U_TData(1,:,i*iterframe))
hold on
Legend{i} = strcat('t=', num2str(t_Data(i*iterframe),'%.2f'));
end
writematrix([x U_TData(1,:,3*iterframe)], 'name_of_file.txt');
  댓글 수: 3
Scott MacKenzie
Scott MacKenzie 2021년 5월 8일
Both
Jamie Al
Jamie Al 2021년 5월 8일
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by