我创建了一个这样的表:
data = table(repmat({'CI'},size(ci.offer)),ci.offer,ci.bid,...
randi(100,size(ci.offer)),randi(100,size(ci.offer)),...
cellstr(ci.time),repmat({'quote'},size(ci.offer)),...
'VariableNames',{'Symbol','AskPrice','BidPrice','AskSize','BidSize',...
'DateTime','Type'});
因为有市场前数据,我需要删除它。我认为声明data(row, :) = [];
会起作用。奇怪的是我看到语句由fprintf
语句执行,
[numlinesData,columns] = size(data)
foundOpen = false;
row = 1;
while(false == foundOpen)
t = data.DateTime(row, :);
Bid = data.BidPrice(row);
Ask = data.AskPrice(row);
dt = datetime(t);
hr = hour(dt);
mint = minute(dt);
if hr > 14 && mint > 29
foundOpen = true;
fprintf('Found open %i', row);
break;
else
fprintf('Deleting row %i\n', row);
data(row, :) = [];
end
row = row + 1;
end
但是当我显示data
时,我看到包括理论上已删除的上市前数据在内的所有行?
data(1:150,:)
我不理解data(row, :) = [];
?
答案 0 :(得分:2)
如果您想继续删除表格的第一行,直到该行符合某些条件,您应该删除该行:
row = row + 1;
如果您遇到性能问题,如果您一次完成所有删除操作,几乎肯定会更快。例如:
rows_to_delete = [];
...
while(false == foundOpen)
...
if hr > 14 && mint > 29
foundOpen = true;
fprintf('Found open %i', row);
break;
else
rows_to_delete(end+1) = row;
end
row = row + 1;
end
data(rows_to_delete, :) = [];