[Scilab-users] eomday
Stefan Du Rietz
sdr at durietz.se
Fri Jul 26 20:29:56 CEST 2013
Hi,
there is a bug in eomday.
+ If there is a leap year between two ordinary years, e.g.
-->Y = [2011 2012 2013]'
Y =
2011.
2012.
2013.
-->M = [10 11 3]'
M =
10.
11.
3.
-->eomday(Y, M)
!--error 15
Submatrix incorrectly defined.
at line 31 of function eomday called by :
eomday(Y, M)
+ Lines 28-33 of the function code, with my "pause" added at 29:
28 [nr,nc] = size(M);
29 pause
30 E( isLeapYear(Y) ) = leap_year( M( isLeapYear(Y)) );
31 E( ~isLeapYear(Y) ) = common_year( M(~isLeapYear(Y)) );
32
33 E = matrix(E,nr,nc);
-->eomday(Y, M)
-1->whereami
whereami called under pause
pause called at line 29 of macro eomday
-1->E( isLeapYear(Y) ) = leap_year( M( isLeapYear(Y)) )
E =
0.
30.
-1->E( ~isLeapYear(Y) ) = common_year( M(~isLeapYear(Y)) );
E( ~isLeapYear(Y) ) = common_year( M(~isLeapYear(Y)) )
!--error 15
Submatrix incorrectly defined.
-1->size( ~isLeapYear(Y) )
ans =
4. 1.
+ Because E is not pre-dimensioned, the index is longer than the vector.
+ Make E a vector with an equal number of elements as M:
-1->E = zeros(1,nr*nc);
+ Now the next lines work:
-1->E( isLeapYear(Y) ) = leap_year( M( isLeapYear(Y)) );
E =
0. 30. 0. 0.
-1->E( ~isLeapYear(Y) ) = common_year( M(~isLeapYear(Y)) )
E =
31. 30. 31. 31.
-1->E = matrix(E,nr,nc)
E =
31.
30.
31.
31.
+ So, a new line 29 is needed:
29 E = zeros(1,nr*nc);
Regards
Stefan
More information about the users
mailing list