Read data from two data files and save them organized into multiples files

2 ビュー (過去 30 日間)
Tesla
Tesla 2021 年 7 月 18 日
コメント済み: Aristo Pacino 2021 年 7 月 20 日
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.

採用された回答

Aristo Pacino
Aristo Pacino 2021 年 7 月 19 日
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 件のコメント
Tesla
Tesla 2021 年 7 月 19 日
I solve this issue by adding a new column to the ans matrix
ans = [time ans];
Aristo Pacino
Aristo Pacino 2021 年 7 月 20 日
Great!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by