Skip to content

Instantly share code, notes, and snippets.

@anjandev
Created August 16, 2017 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anjandev/c640ba87111244e1734fbd88b4629a66 to your computer and use it in GitHub Desktop.
Save anjandev/c640ba87111244e1734fbd88b4629a66 to your computer and use it in GitHub Desktop.
Copy every Nth line algorithm (octave)
clear all
function newFinal = addAndConcat(oldFinal, newEnding)
% Copy every 30th line
N=30;
fid = newEnding;
% Delete top 3 lines
C = textread(fid, '%s', 'Delimiter', '\n', 'HeaderLines',3);
C = C(1:N:length(C));
newFinal = [oldFinal; C];
end
function newFinal = firstFileAddAndConcat(file)
% Copy every 30th line
N=30;
fid = file;
% Delete top 3 lines
newFinal = textread(fid, '%s', 'Delimiter', '\n', 'HeaderLines',3);
newFinal = newFinal(1:N:length(newFinal));
end
newFinal = firstFileAddAndConcat('.csv');
newFinal = addAndConcat(newFinal, '.csv');
newFinal = addAndConcat(newFinal, '.csv');
% etc.
fid = fopen('FINAL_ALL.txt','wt');
formatSpec = '%s\n';
[nrows,ncols] = size(newFinal);
for row = 1:nrows
fprintf(fid,formatSpec,newFinal{row,:});
end
fclose(fid);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment