Slicing arrays and save it in the file
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Elzbieta
el 11 de Jul. de 2024
Comentada: Mathieu NOE
el 16 de Jul. de 2024
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 comentarios
Respuesta aceptada
Mathieu NOE
el 11 de Jul. de 2024
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 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Data Import and Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!