How to save part of the data in text file?

4 ビュー (過去 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 Center および File ExchangeOctave についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by