dangling number producing strange display

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

dangling number producing strange display

CdeMills
Hello,

I had a hard time understanding the following behaviour:

x = 0
for indi=(1:10) 120
x=x+1;
end

during execution, I got:
ans =  120 [repeated 10 times]

The dangling '120' was introduced by accident while modifying some file. Is it legal syntax ? What is the behaviour under MatLab ?

Regards

Pascal
Reply | Threaded
Open this post in threaded view
|

Re: dangling number producing strange display

Richard Crozier
On 04/12/2013 18:07, CdeMills wrote:

> Hello,
>
> I had a hard time understanding the following behaviour:
>
> x = 0
> for indi=(1:10) 120
> x=x+1;
> end
>
> during execution, I got:
> ans =  120 [repeated 10 times]
>
> The dangling '120' was introduced by accident while modifying some file. Is
> it legal syntax ? What is the behaviour under MatLab ?
>
> Regards
>
> Pascal
>

legal in Matlab, equivalent to just writing

for indi=(1:10)
120
x=x+1;
end

In ML

 >> x = 0
for indi=(1:10) 120
x=x+1;
end

x =

      0.0000e+000


ans =

    120.0000e+000


ans =

    120.0000e+000


<snip>


ans =

    120.0000e+000


ans =

    120.0000e+000

 >> x

x =

     10.0000e+000


Richard

--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.