用MATLAB删除excel文件中的行
我将使用Matlab删除excel文件的行 具体来说,我已经删除了一些满足条件的值。 (在这种情况下,我删除了超出2西格玛(统计分布)的元素) 但我遇到了不希望出现的结果,因为它们只会删除值并将位置保留为空。 因此,我正在寻找删除行或移动元素以不留空格的方法用MATLAB删除excel文件中的行,excel,matlab,Excel,Matlab,我将使用Matlab删除excel文件的行 具体来说,我已经删除了一些满足条件的值。 (在这种情况下,我删除了超出2西格玛(统计分布)的元素) 但我遇到了不希望出现的结果,因为它们只会删除值并将位置保留为空。 因此,我正在寻找删除行或移动元素以不留空格的方法 %**Open the file** fullFileName = [pwd '\Eurostoxx50_7월.xlsm']; excel = actxserver('Excel.Application'); file = excel.W
%**Open the file**
fullFileName = [pwd '\Eurostoxx50_7월.xlsm'];
excel = actxserver('Excel.Application');
file = excel.Workbooks.Open(fullFileName);
sheet1=excel.Worksheets.get('Item', 'Inputsheet');
size_of_pd = size(PriceDifference2);
size_of_pd = size_of_pd(1);
%**Get the index where I want to remove**
m = mean(PriceDifference2);
s = std(PriceDifference2);
v1=m+2*s
v2=m-2*s
TF1 = PriceDifference2(:) >= v1 ;
TF2 = PriceDifference2(:) <= v2 ;
% combine them
TFall = TF1 | TF2;
%remove the elements
for i = 1:1:size_of_pd
if TFall(i) > 0
first_cell = strcat('B',num2str(i+34));
last_cell = strcat('Q',num2str(i+34));
range1=get(sheet1,'Range', first_cell,last_cell);
range1.Value=[];
end
end
file.Save;
file.Close;
delete(excel);
但是我想删除下面所有的空格
0.002678839 0 0.479452055 3204.381729 2850 41.1 P -1.472671354
0.002678839 0 0.479452055 3204.381729 2900 48.9 P -1.508805266
0.002678839 0 0.479452055 3204.381729 2925 53.3 P -1.341898247
0.002678839 0 0.479452055 3204.381729 3350 210.8 P 12.3246967
0.002678839 0 0.479452055 3204.381729 3375 226.5 P 11.98361578
0.002678839 0 0.479452055 3204.381729 3400 243.1 P 11.31755056
0.002678839 0 0.479452055 3204.381729 3425 260.4 P 10.86345463
0.002678839 0 0.479452055 3204.381729 3350 210.8 P 12.3246967
0.002678839 0 0.479452055 3204.381729 3375 226.5 P 11.98361578
0.002678839 0 0.479452055 3204.381729 3400 243.1 P 11.31755056
0.002678839 0 0.479452055 3204.381729 3425 260.4 P 10.86345463
我用愚蠢的方法解决了它。
只需复制和粘贴多次
fullFileName = [pwd '\Eurostoxx50_7월.xlsm'];
if isempty(fullFileName)
% User clicked Cancel.
return;
end
excel = actxserver('Excel.Application');
sheet1=excel.Worksheets.get('Item', 'Inputsheet');
start_point = 34;
size_of_pd = size(PriceDifference2);
size_of_pd = size_of_pd(1);
%last_cell = strcat('Q',num2str(size_of_pd ));
first_cell = strcat('Q',num2str(start_point+1));
last_cell = strcat('Q',num2str(size_of_pd));
range1=get(sheet1,'Range', first_cell,last_cell);
PD_EXCEL = range1.value;
m = mean(PD_EXCEL);
s = std(PD_EXCEL);
v1 = m+2*s;
v2 = m-2*s;
TF1 = PD_EXCEL(:) >= v1 ;
TF2 = PD_EXCEL(:) <= v2 ;
% combine them
TFall = TF1 | TF2;
for i = 1:1:size_of_pd
if TFall(i) > 0
first_cell = strcat('B',num2str(i+start_point));
last_cell = strcat('Q',num2str(i+start_point));
range1= get(sheet1,'Range', first_cell,last_cell);
range1.Value = [];
end
end
for i = size_of_pd:-1:1
if TFall(i)>0
copy_first_cell = strcat('B',num2str(i+start_point+1));
copy_last_cell = strcat('Q',num2str(size_of_pd+start_point));
first_cell = strcat('B',num2str(i+start_point));
last_cell = strcat('Q',num2str(size_of_pd+start_point-1));
range1=get(sheet1,'Range', copy_first_cell,copy_last_cell);
range2 = get(sheet1,'Range',first_cell,last_cell);
range2.Value=range1.value;
end
end
first_cell = strcat('B',num2str(start_point + sum(TFall(:)==0)));
last_cell = strcat('Q',num2str(start_point+size_of_pd));
range1 = get(sheet1,'Range', first_cell,last_cell);
range1.Value = [];
file.Save;
file.Close;
delete(excel);
fullFileName=[pwd'\Eurostoxx50\u 7월.xlsm'];
如果为空(完整文件名)
%用户单击了“取消”。
回来
终止
excel=actxserver('excel.Application');
sheet1=excel.Worksheets.get('Item','Inputsheet');
起始点=34;
尺寸=尺寸(价差2);
_pd的大小=_pd的大小(1);
%最后一个单元格=strcat('Q',num2str(大小为\u pd));
第一个单元格=strcat('Q',num2str(起始点+1));
最后一个单元格=strcat('Q',num2str(大小为\u pd));
range1=获取(sheet1,'Range',第一个单元格,最后一个单元格);
PD_EXCEL=范围1.0;
m=平均值(PD_EXCEL);
s=标准(PD_EXCEL);
v1=m+2*s;
v2=m-2*s;
TF1=PD_EXCEL(:)>=v1;
TF2=PD_EXCEL(:)0
第一个单元格=strcat('B',num2str(i+起点));
最后一个单元格=strcat('Q',num2str(i+起点));
range1=获取(sheet1,'Range',第一个单元格,最后一个单元格);
范围1.值=[];
终止
终止
对于i=尺寸为-1:1
如果TFall(i)>0
复制第一个单元格=strcat('B',num2str(i+起始点+1));
复制最后一个单元格=strcat('Q',num2str(大小+起始点));
第一个单元格=strcat('B',num2str(i+起点));
最后一个单元格=strcat('Q',num2str(pd的大小+起始点-1));
range1=获取(sheet1,'Range',复制第一个单元格,复制最后一个单元格);
range2=获取(表1,“范围”、第一个单元格、最后一个单元格);
range2.值=range1.值;
终止
终止
第一个单元格=strcat('B',num2str(起点+总和(TFall(:)==0));
最后一个单元格=strcat('Q',num2str(起始点+大小);
range1=获取(sheet1,'Range',第一个单元格,最后一个单元格);
范围1.值=[];
文件保存;
文件。关闭;
删除(excel);
您的矩阵是什么类型的数据?细胞,结构,双重?
fullFileName = [pwd '\Eurostoxx50_7월.xlsm'];
if isempty(fullFileName)
% User clicked Cancel.
return;
end
excel = actxserver('Excel.Application');
sheet1=excel.Worksheets.get('Item', 'Inputsheet');
start_point = 34;
size_of_pd = size(PriceDifference2);
size_of_pd = size_of_pd(1);
%last_cell = strcat('Q',num2str(size_of_pd ));
first_cell = strcat('Q',num2str(start_point+1));
last_cell = strcat('Q',num2str(size_of_pd));
range1=get(sheet1,'Range', first_cell,last_cell);
PD_EXCEL = range1.value;
m = mean(PD_EXCEL);
s = std(PD_EXCEL);
v1 = m+2*s;
v2 = m-2*s;
TF1 = PD_EXCEL(:) >= v1 ;
TF2 = PD_EXCEL(:) <= v2 ;
% combine them
TFall = TF1 | TF2;
for i = 1:1:size_of_pd
if TFall(i) > 0
first_cell = strcat('B',num2str(i+start_point));
last_cell = strcat('Q',num2str(i+start_point));
range1= get(sheet1,'Range', first_cell,last_cell);
range1.Value = [];
end
end
for i = size_of_pd:-1:1
if TFall(i)>0
copy_first_cell = strcat('B',num2str(i+start_point+1));
copy_last_cell = strcat('Q',num2str(size_of_pd+start_point));
first_cell = strcat('B',num2str(i+start_point));
last_cell = strcat('Q',num2str(size_of_pd+start_point-1));
range1=get(sheet1,'Range', copy_first_cell,copy_last_cell);
range2 = get(sheet1,'Range',first_cell,last_cell);
range2.Value=range1.value;
end
end
first_cell = strcat('B',num2str(start_point + sum(TFall(:)==0)));
last_cell = strcat('Q',num2str(start_point+size_of_pd));
range1 = get(sheet1,'Range', first_cell,last_cell);
range1.Value = [];
file.Save;
file.Close;
delete(excel);