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!