【问题标题】:Please anyone be so kind help! Matlab [closed]请任何人提供帮助! Matlab [关闭]
【发布时间】:2014-03-03 21:58:24
【问题描述】:

我有年、月、日的数据。我希望这在 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)

【问题讨论】:

  • 到目前为止你尝试了什么?另请记住,matlab 使用空格 ` ` 和 , 作为矩阵元素之间的分隔符 - 您格式化日期的方式具有误导性。

标签: matlab


【解决方案1】:

最简单的方法是重塑矩阵并相应地使用它。我演示了以美国(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

【讨论】:

  • 非常感谢!!!我只是 Matlab 的初学者(专门编程)
  • @tutatran,如果答案恰当地回答了您的问题,consider accepting it by clicking on the tick-mark on the left.
  • 我尝试了很少的时间来点击接受 - 答案,但它不起作用。我想也许我是这里的新成员,该网站并没有为我完全激活所有功能工具。有人可以通过某种方式为这个网站付费吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-26
  • 1970-01-01
  • 2021-02-02
  • 1970-01-01
相关资源
最近更新 更多