How to save part of the data in text file?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jamie Al
am 7 Mai 2021
Bearbeitet: Scott MacKenzie
am 8 Mai 2021
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/611210/image.png)
0 Kommentare
Akzeptierte Antwort
Scott MacKenzie
am 8 Mai 2021
Bearbeitet: Scott MacKenzie
am 8 Mai 2021
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Octave finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!