如何分别显示列中的日期?

How to display the dates from a column separately?

我有一组数据,第 1 列显示日期(以 MATLAB 序列号形式),第 2 列显示降雨量,如下所示:

x = [ 22029   81 
      23040   90.2
      26701   90.2
      28223  188
      36973   92
      38386   99.8
      40580  117.8];

到目前为止我的代码是:

out = x(x(:,2) > 180,:,1); %gets all the dates with rainfall greater than 180
out2 = x(x(:,2) > 80,:,1); %gets all the dates with rainfall greater than 80
c1 = out(:,1);
c2 = out2(:,1);
rain = datestr(c1); %converts from MATLAB serial number to date
rain2 = datestr(c2); %converts from MATLAB serial number to date
X = sprintf('Heaviest rainfall will occur on %s.',rain);
X2 = sprintf('Heavy rainfall will occur on %s.',rain2);
disp(X)
disp(X2) 

我的 disp(X) 工作并显示:

Heaviest rainfall will occur on 08-Apr-0077.

但是我的 disp(X2) 不工作并显示

Heavy rainfall will occur on 22002003968447-------AJFAMFFpaepaeernbrrbb-------0000000000011166770010337151.

如何修复 disp(X2) 的代码,使其显示:

Heavy rainfall will occur on 23-Apr-0060, 29-Jan-0063, 06-Feb-0073, 08-Apr-0077, 24-Mar-0101, 04-Feb-0105, 04-Feb-0105.

发生这种情况是因为矩阵在 MATLAB 中按列主顺序存储。您可以在使用 sprintf 函数之前重新排序 Rain2 字符数组,如下所示:

rain2(:,end+1) = ',';     rain2(end) = '.';   %For , in between and . at the end
rain2 = rain2.';  %Reordering
X2 = sprintf('Heavy rainfall will occur on %s', rain2);

结果:

>> X2
X2 =
    'Heavy rainfall will occur on 23-Apr-0060,29-Jan-0063,06-Feb-0073,08-Apr-0077,24-Mar-0101,04-Feb-0105,07-Feb-0111.'