Is there a way to only read every third row of a .csv file?
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Petch Anuwutthinawin
el 10 de Jul. de 2021
I need my code to read every third row and every column of a .csv file and save it seperately. For example I need the third row, sixth row, ninth row saved but not the first and second rows.
0 comentarios
Respuesta aceptada
LO
el 10 de Jul. de 2021
Editada: LO
el 10 de Jul. de 2021
import the file and the use logic indexing, double check if it is selecting the right rows, if not just change the index array to index = 1:3:height(forcetest), I am not sure which rows you need
% filename = 'C:\YOURPATH\forcetest.csv';
filename = 'C:\Users\Livio\Downloads\forcetest.csv';
delimiter = ',';
formatSpec = '%f%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'EmptyValue', NaN, 'ReturnOnError', false);
fclose(fileID);
forcetest = table(dataArray{1:end-1}, 'VariableNames', {'VarName1','VarName2','VarName3'});
clearvars filename delimiter formatSpec fileID dataArray ans;
index = 1:2:height(forcetest);
selected_table = forcetest(index,:);
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Import from MATLAB 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!