As we don't yet know how to identify the files to be processed, nor how exactly the data is to be exported to excel, the below just focuses on the file import:
filelist = {'b1-moment-z-rfile.txt', 'b2-moment-z-rfile.txt', 'b3-moment-z-rfile.txt'};
datatoexport = cell(size(filelist));
for filenum = 1:numel(filelist)
wholecontent = readtable(filelist{filenum});
datatoexport{filenum} = wholecontent(end, :);
end
With the above, you will get a warning for each file that matlab modifies the header to make it valid variable names (it removes the ( and " and replaces the - by _). The warning can be turned off with
warning('off', 'MATLAB:table:ModifiedAndSavedVarnames');
or matlab can be told not to do the replacement (thus keeping the (" in the variable names) with the 'PreserveVariableNames', false option of readtable.
Once details of how to identify files and what export is desired, the above can be modified accordingly.
4 Comments
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/511215-code-to-extract-data-from-txt-file-to-excel#comment_811106
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/511215-code-to-extract-data-from-txt-file-to-excel#comment_811106
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/511215-code-to-extract-data-from-txt-file-to-excel#comment_811220
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/511215-code-to-extract-data-from-txt-file-to-excel#comment_811220
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/511215-code-to-extract-data-from-txt-file-to-excel#comment_811228
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/511215-code-to-extract-data-from-txt-file-to-excel#comment_811228
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/511215-code-to-extract-data-from-txt-file-to-excel#comment_811240
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/511215-code-to-extract-data-from-txt-file-to-excel#comment_811240
Sign in to comment.