필터 지우기
필터 지우기

How do we convert multiple csv files to execl file in matlab ?

조회 수: 2 (최근 30일)
ahmed obaid
ahmed obaid 2017년 5월 24일
편집: Walter Roberson 2017년 5월 24일
Dear experiences ...
i have multiple csv files in certain folder ("D:\original")(100+), i need to convert these files from csv to xls files and store it in ("D:\master").. i have used the following code but its give me an error in xlsread ..
Error using xlsread (line 128)
XLSREAD unable to open file 'c.csv'.
File 'C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\c.csv' not found.
the code is in the following:
orginal='D:\original'
d=dir([original '\*.csv']);
files={d.name};
for k=1:numel(files)
old_name=files{k};
[~,~,b] = xlsread(old_name) ;
new_name=strrep(old_name,'csv','xls')
xlswrite(new_name,b);
end
thanks

채택된 답변

ES
ES 2017년 5월 24일
orginal='D:\original'
d=dir([orginal '\*.csv']); %Spelling mistake here
files={d.name};
for k=1:numel(files)
filename=files{k};
fullname = fullfile(orginal,filename );%Getting the fullfile name
[~,~,b] = xlsread(fullname) ;
new_name=strrep(fullname,'csv','xls')
xlswrite(new_name,b);
end
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 5월 24일
masterdir = 'D:\master'
xlswrite( fullfile( masterdir, new_name), b)
Walter Roberson
Walter Roberson 2017년 5월 24일
편집: Walter Roberson 2017년 5월 24일
[filedir, basename, ext] = fileparts(filename);
new_file = fullfile( masterdir, [basename '.xlsx']);
and you can get rid of some of your other lines like
new_name=strrep(fullname,'csv','xlsx')

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by