xlswrite 覆盖现有文件

xlswrite overwrite existing file

我有 53 个 xls table(ch_1、ch_2、...),然后将它们用作神经网络的输入。之后将 NN 结果写入新的 xls 和 csv。

clc
clear all
files=dir('*.xls');
for i=1:length(files(:,1))
    aa=xlsread(files(i).name);
    fprintf('step: %d\n', i);
datanameXls = ['channel_' num2str(i) '.xls'];
datanameCsv = ['channel_' num2str(i) '.csv'];

a17=aa(:,1);
b17=aa(:,4);
p=size(a17);
c17=zeros(144,31);


% Create a Fitting Network
hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize);


% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;


% Train the Network
[net,tr] = train(net,inputs,targets);
% Test the Network
outputs = net(inputs);
A= zeros(4464, 2);
A = [o, outputs'];
A(A<0)=0;
csvwrite(datanameCsv, A);
fprintf('csv is written \n');
xlswrite(datanameXls, A);
fprintf('xls is written \n');
end

问题是:当我用一个、两个直到 9 table 尝试这个程序时,我通过 xlswrite 保存的结果是真实的,但是当我用 52 table 尝试它时,我得到一个错误的 table 因为例如 ch_1 被 ch_10.
覆盖 有什么想法吗???

我解决了我的问题。 'dir' 先读 ch_10 到 ch_19 然后 ch_1。我确实重命名了我的所有文件并且它现在可以工作 correctly.I 做了以下重命名所有文件:

    clc
clear all
files = dir('*.xls');
 for k=1:length(files(:,1))
     oldFileName = sprintf('ch_%dMonth_1.xls',k);
     newFileName = sprintf('%03d.xls',k);
     movefile(oldFileName,newFileName);
 end