Slicing arrays and save it in the file
4 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have a file of the following form:
data condition device
-297.367190000000 8 1
-295.132890000000 8 1
-268.007000000000 8 2
-268.007000000000 8 2
-262.109380000000 7 1
-263.296880000000 7 1
-263.562500000000 7 2
-263.562500000000 7 2
-258.973210000000 6 1
-255.209820000000 6 1
-255.209820000000 6 2
-255.209820000000 6 2
I would like to process the data being a slice of array for the given condition and device for instance one slice would be:
-297.367190000000 8 1
-295.132890000000 8 1
and save the result in file with the following format for instance for the data above:
dataProcessed_condition8_device1
How could I cut such slice and save it in the file of the described format?
Regards
Elzbieta
0 件のコメント
採用された回答
Mathieu NOE
2024 年 7 月 11 日
hello
with your input data in attachment, try this code :
% load data
data = readmatrix('data.txt'); % or readtable if you prefer
% select condition & device
condition = 8;
device = 1;
% select rows that satisfy both conditions
ind = (data(:,2) == condition) & (data(:,3) == device);
data_out = data(ind,:); %
% export to txt file
filename_out = "dataProcessed_condition" + num2str(condition) + "_device" + num2str(device)+ ".txt";
writematrix(data_out,filename_out,"Delimiter","tab");
% edit the file
type(filename_out)
0 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!