无法在EXCEL中的新行中打印MATLAB数据

我正在试图获取这些数据,以便在每次获得结果时将其显示在新行中。 不过,我现在只能在Excel中获得一行。

– >我猜我无法做的事情是,一旦一个数据点被input/写入,matlab需要AUTOMATICALLY转到下一行/行…目前没有这样做。

任何帮助感激,


figure; prices_pred = zeros(size(prices)); prices_pred(750) = prices(750); time_show = 15000; for t = 750:length(prices)-1 price180 = prices(t-179:t); price360 = prices(t-359:t); price720 = prices(t-719:t); dp = theta0 + theta(1); prices_pred(t+1) = prices(t) + dp; if (t-750 < time_show) x1 = 0:t-750; y1 = prices(750:t); x2 = 0:t-749; y2 = prices_pred(750:t+1); end if (t-750 > time_show) x1 = 0:time_show; y1 = prices(t-time_show:t); x2 = 0:time_show+1; y2 = prices_pred(t-time_show:t+1); end plot(x1,y1,'b*',x2,y2,'m*'); drawnow; disp(prices_pred(t+1)); disp(prices(t)); disp(dp); if (T > 750) T = {T;table(prices_pred(t), prices(t),dp)}; else T = table(prices_pred(t), prices(t),dp); end filename = 'test.csv'; writetable(T, filename); 

写入Excel的简单方法是使用单元格数组和xlswrite命令。

用下面给出的variables,其步骤如下…

variables:

 eventDate = [{'2016-02-10'};{'2016-02-11'};{'2016-02-12'}]; eventTime = [931;931;1600]; eventValue = [{'open'};{'open'};{'close'}]; xlsDir = 'c:\xls\'; xlsFilename = [xlsDir,'output.xls']; 

1)预先分配你的单元格数组:

 nevent = length(eventTime); xxcell = cell(nevent+1,3); 

2)为您的单元格数组创build标题行:

 irow = 1; icol = 1; xxcell{irow,icol} = 'Date'; icol = icol + 1; xxcell{irow,icol} = 'Time'; icol = icol + 1; xxcell{irow,icol} = 'Value'; icol = icol + 1; 

3)将您的数据添加到单元格数组:

 for ievent = 1:nevent irow = ievent + 1; icol = 1; xxcell{irow,icol} = eventDate{ievent}; icol = icol + 1; xxcell{irow,icol} = eventTime(ievent); icol = icol + 1; xxcell{irow,icol} = eventValue{ievent}; icol = icol + 1; end 

4)写入Excel:

 try xlswrite(xlsFilename, xxcell); catch disp('xlswrite error'); end 

我没有尝试使用可writetable命令,但是这种方法工作得不错。