请有人帮忙! MATLAB

时间:2014-03-03 21:58:24

标签: matlab

我有年,月,日的数据。我希望这在Matlab中显示为年,月,日,并且不知道该怎么做。

X=(2014,01,02 2014,01,03 2014,01,07 2014,01,08 2014,01,09 2014,01,10 2014,01,13 
2014,01,14 2014,01,15 2014,01,16 2014,01,17 2014,01,20 2014,01,21 2014,01,22 
2014,01,23 2014,01,24 2014,01,27 2014,01,28 2014,01,29 2014,01,30 2014,01,31 
2014,02,03 2014,02,04 2014,02,05 2014,02,06 2014,02,07 2014,02,10 2014,02,11 
2014,02,12 2014,02,13 2014,02,14 2014,02,17 2014,02,18 2014,02,19 2014,02,20 
2014,02,21 2014,02,24 2014,02,25 2014,02,26 2014,02,27 2014,02,28 2014,03,03)

1 个答案:

答案 0 :(得分:4)

最简单的方法是重塑矩阵并相应地使用它。我演示了以美国(MM / DD / YYYY)格式重塑和打印所有日期的方法。

X=[2014,01,02 2014,01,03 2014,01,07 2014,01,08 2014,01,09 2014,01,10 2014,01,13 2014,01,14 2014,01,15 2014,01,16 2014,01,17 2014,01,20 2014,01,21 2014,01,22 2014,01,23 2014,01,24 2014,01,27 2014,01,28 2014,01,29 2014,01,30 2014,01,31 2014,02,03 2014,02,04 2014,02,05 2014,02,06 2014,02,07 2014,02,10 2014,02,11 2014,02,12 2014,02,13 2014,02,14 2014,02,17 2014,02,18 2014,02,19 2014,02,20 2014,02,21 2014,02,24 2014,02,25 2014,02,26 2014,02,27 2014,02,28 2014,03,03];

X_in_better_format = reshape(X,3,42)';

for it = 1:size(X_in_better_format,1)
sprintf('The date is %d/%d/%d',X_in_better_format(it,2),X_in_better_format(it,3),X_in_better_format(it,1)) %US Format
end