Read data from two data files and save them organized into multiples files
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Tesla
am 18 Jul. 2021
Kommentiert: Aristo Pacino
am 20 Jul. 2021
I want to write a code that reads X coordinates from x.dat and Y coordinates from y.dat, then save X Y coordinates for each particle in different file with 3 columns: Time, X, Y. (if i have for example 10 particles i will get 10 files)
In the picture the form of the data. Each columns is for each particle, and lines are for the times iterations.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/688273/image.png)
0 Kommentare
Akzeptierte Antwort
Aristo Pacino
am 19 Jul. 2021
x=load('x.dat');
y=load('y.dat');
nsize = size(x);
n = nsize(2); %%%% selecting only column of matrix
I am assuming x.dat and y.dat has same coloumns. Also try inserting the time in the ans matrix
for i=1:n
ans = [time(i),x(:,i),y(:,i)];
filename = strcat('test',num2str(i),'.dat')
save(filename,'ans','-ascii')
end
3 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!