필터 지우기
필터 지우기

how to import data from text file to excel sheet for multiple text files

조회 수: 3 (최근 30일)
KALYAN KUMAR
KALYAN KUMAR 2014년 11월 11일
편집: Ave Linn 2015년 4월 15일
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??

답변 (1개)

Ave Linn
Ave Linn 2015년 4월 15일
편집: Ave Linn 2015년 4월 15일
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;

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by