error in using year()
1 次查看(过去 30 天)
显示 更早的评论
I typed exactly the same code as in the reference provided below:
Year = year('05-Aug-2003')
and I get
Year =
2002
2002
2002
2002
2002
2002
2002
2002
2002
2002
2002
Why is that? Thanks.
Reference:
2 个评论
回答(1 个)
Fangjun Jiang
2016-3-1
编辑:Fangjun Jiang
2016-3-1
There must be a variable called "year" in the workspace. Try this:
year=2002*ones(120,1);
Year = year('05-Aug-2003')
It got your answer.
Try this
year=1:120;
Year=year('05-Aug-2003')
Year =
48 53 45 65 117 103 45 50 48 48 51
notice
>> double('05-Aug-2003')
ans =
48 53 45 65 117 103 45 50 48 48 51
It turned out it converted the string '05-Aug-2003' into double numbers and used the numbers to index the existing matrix "year". The size of "year" happens to be large enough so the "Index exceeds matrix dimensions" error didn't happen.
I don't like this behavior.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!