0
我打算使用Matlab刪除excel文件的行使用MATLAB刪除excel文件的行
具體來說,我已經刪除了一些滿足條件的值。 (在這種情況下,我刪除了2 sigma以外的元素(統計分佈))
但是,我遇到了不希望的結果,導致它們只刪除值並保持空白位置。 所以我正在尋找刪除行或移動元素以使空格不變的方法。
%**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);
更具體地說,結果看起來像下面在一個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
但我想刪除所有的空間,如下面
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
什麼樣的數據類型是你的矩陣? cell,struct,double? –