f

#### for loops and the identity matrix

```I am completely new to matlab and have been practicing "for-loops"

when I generate

"x=eye(3)"

I obviously receive the identity matrix of three columns and three rows.

however,

"for x=eye(3)
end"

puts out a single column "1,0,0"

It seems trivial, but I would like to remove all misconceptions from my mind at this early point.  Is there a logical reason for this seeming discrepency?
```
 0
Erik
12/23/2016 1:13:03 PM
comp.soft-sys.matlab 211264 articles. 26 followers. lunamoonmoon (257) is leader.

2 Replies
833 Views

Similar Articles

[PageSpeed] 13

```On 12/23/2016 7:13 AM, Erik Anderson wrote:
> I am completely new to matlab and have been practicing "for-loops"
>
> when I generate
> "x=eye(3)"
>
> I obviously receive the identity matrix of three columns and three rows.
>
> however,
> "for x=eye(3)
> end"
>
> puts out a single column "1,0,0"

No.

> It seems trivial, but I would like to remove all misconceptions from my
> mind at this early point. Is there a logical reason for this seeming
> discrepency?

Ayup...and it's documented besides... :)

Try

for x=eye(3)
disp(x)
end

and read the doc for FOR carefully...
```
 0
dpb
12/23/2016 1:46:33 PM
```On 12/23/2016 7:46 AM, dpb wrote:
....

> Try
>
> for x=eye(3)
> disp(x)
> end
>
> and read the doc for FOR carefully...

Altho the above should make it patently clear, try

iter=0;
for x=eye(3)
iter=iter+1;
fprintf('Iteration: %d\n',iter)
disp(x)
end

as a more user-friendly test/demo...
```
 0
dpb
12/23/2016 2:39:31 PM