The error in the given code is a dimension mismatch between x
and y
.
The reason for this error is that ":
" creates an array based on the step value, but it does not take into consideration the final value, which can result in arrays with different lengths.
To fix it, we need to change either x
or y
such that the lengths match. We can do this by changing the step value of y
to 1 instead of 2. The corrected code should look like this:
main.m36 chars4 lines
Alternatively, we can also change the range of x
so that the lengths of x
and y
match. This can be achieved by changing the upper bound of x
from 10
to 9
. The corrected code using this method should look like this:
main.m35 chars4 lines
gistlibby LogSnag