how to import data from text file to excel sheet for multiple text files
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i need to import data from text file to excel file for 50*3 data and for many text files how should i need to convert.. can any one solve this??
0 commentaires
Réponses (1)
Ave Linn
le 15 Avr 2015
Modifié(e) : Ave Linn
le 15 Avr 2015
I have the same issue. Attached is the text file out of several which I wish to write in one excel file with function. And the code I tried is attached below,
clc; clear all;
delimiter = '\t';
startRow = 4;
endRow = 103;
formatSpec = '%s%s%s%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%[^\n\r]';
fileID = fopen(filename,'r');
newArray = textscan(fileID, formatSpec, endRow(1)-startRow(1)+1, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines', startRow(1)-1, 'ReturnOnError', false); for block=2:length(startRow) frewind(fileID); dataArrayBlock = textscan(fileID, formatSpec, endRow(block)-startRow(block)+1, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines', startRow(block)-1, 'ReturnOnError', false); for col=1:length(newArray) newArray{col} = [newArray{col};dataArrayBlock{col}]; end end fclose(fileID);
newArray([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]) = cellfun(@(x) num2cell(x), newArray([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]), 'UniformOutput', false); excelexport = [newArray{1:end-1}]; export ('excelexport','XLSFile','output.xlsx'); clearvars filename delimiter startRow endRow formatSpec fileID newArray ans;
0 commentaires
Voir également
Catégories
En savoir plus sur Text Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!