How to specify the input folder location and save output in specified folder

조회 수: 16 (최근 30일)
Hi,
I have the following code:
clc;
clear all;
close all;
filename='tool1.xlsx';
[score, M]=xlsread(filename);
M(1,:)=[];
M(:,1)=[];
M(:,3)=[];
score(:,2:3)=[];
filterdata=[M num2cell(score)];
outputfilename=regexp(filename,'.xlsx','split');
outputdatafilename=['output_' outputfilename{1} '.xlsx'];
xlswrite(outputdatafilename,filterdata)
(1) I want to put input data in one folder and save out put in another (specified folder). Pl help how can I do this.
(2) I want to read all '.xlsx' files in a given folder one by one and save corresponding output in another specified folder. Pl also help how can I do this( I have give two tool's data).
Sincerely, Mekala

채택된 답변

Guillaume
Guillaume 2016년 2월 26일
편집: Guillaume 2016년 2월 26일
Use |fullfile to build paths:
sourcefolder = 'C:\some\folder';
destinationfolder = 'C:\some\other\folder';
[score, M] = xlsread(fullfile(sourcefolder, filename));
%...
xlswrite(fullfile(destinationfolder, outputdatafilename), filterdata);
Use dir to get the content of a folder:
sourcefolder = 'C:\some\folder';
fcontent = dir(fullfile(sourcefolder, '*.xlsx')); %fcontent is a column vector of structures
for file = fcontent'
filename = file.name;
[score, M] = xlsread(fullfile(sourcefolder, filename));
%...
end
By the way than regexp to get the parts of the filename is with fileparts:
[~, outputfilename] = fileparts(filename);
outputdatafilename = sprintf('output_%s.xlsx' outputfilename);
Although in your case, I don't understand why you're removing the '.xlsx' only to add it back on the next line, so you might as well simply do:
outputdatafilename = ['output_' filename];
  댓글 수: 3
Guillaume
Guillaume 2016년 2월 26일
Well, you specify it in xlswrite of course. I simply forgot to include it in my example.
Fixed now.
Kanakaiah Jakkula
Kanakaiah Jakkula 2016년 2월 26일
Sir, May I ask one more thing, time format in my output file is different from input file. Can it be fixed?
My input time is :
2015/2/6 23:34:24
2015/2/7 22:34:24
2015/2/8 22:56:24
but in the output it is changed to:
2015/2/6 下午 11:34:24
2015/2/7 下午 10:34:24
2015/2/8 下午 10:56:24
Sincerely,

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by