Re: Interpreting the colon operator



Thanks, Roger.

Just now I realized that h is a 6x6 matrix so the answer for 6.
(Please correct me if my understanding is wrong)

I tried this by using the print statement inside the loop.

for k=1:N;
Av(k,:,:)=i*m*h ; % h is a 6 x 6 Matrix.
Av
end;

I was expecting a 6 x 6 matrix for each run of the loop. Instead I am
getting six 1 x 6 matrices in the first iteration of the for loop.
For the second the third iterations I am getting six 2 x 6 and six 3
x 6 matrices. I have given the outputs below. Could you please let me
know why? Thanks again.

***********************************************************
Gav(:,:,1) =

1.0e+036 *

Columns 1 through 4

-3.2754 - 1.3819i 4.2235 - 0.1430i -3.2754 - 1.3819i -1.0137 -
2.6399i

Columns 5 through 6

2.3129 - 0.5534i -0.4026 + 2.0435i

Gav(:,:,2) =

1.0e+036 *

Columns 1 through 4

4.2235 - 0.1430i NaN + NaNi 4.2235 - 0.1430i -2.0146 +
2.2094i

Columns 5 through 6

-0.1540 - 2.4368i 1.6118 + 1.3688i

Gav(:,:,3) =

1.0e+036 *

Columns 1 through 4

-3.2754 - 1.3819i 4.2235 - 0.1430i -3.2754 - 1.3819i -1.0137 -
2.6399i

Columns 5 through 6

2.3129 - 0.5534i -0.4026 + 2.0435i

Gav(:,:,4) =

1.0e+036 *

Columns 1 through 4

-1.0137 - 2.6399i -2.0146 + 2.2094i -1.0137 - 2.6399i -2.5135 -
0.0715i

Columns 5 through 6

-2.0102 - 0.9590i 0.1236 - 1.9961i

Gav(:,:,5) =

1.0e+036 *

Columns 1 through 4

2.3129 - 0.5534i -0.1540 - 2.4368i 2.3129 - 0.5534i -2.0102 -
0.9590i

Columns 5 through 6

-1.9317 + 0.6959i -1.8819 + 0.1889i

Gav(:,:,6) =

1.0e+036 *

Columns 1 through 4

-0.4026 + 2.0435i 1.6118 + 1.3688i -0.4026 + 2.0435i 0.1236 -
1.9961i

Columns 5 through 6

-1.8819 + 0.1889i -1.3358 + 1.1737i

Gav(:,:,1) =

1.0e+036 *

Columns 1 through 4

-3.2754 - 1.3819i 4.2235 - 0.1430i -3.2754 - 1.3819i -1.0137 -
2.6399i
-2.5135 - 0.0715i -1.0137 - 2.6399i -2.0146 + 2.2094i -1.0137 -
2.6399i

Columns 5 through 6

2.3129 - 0.5534i -0.4026 + 2.0435i
-2.5135 - 0.0715i -2.0102 - 0.9590i

Gav(:,:,2) =

1.0e+036 *

Columns 1 through 4

4.2235 - 0.1430i NaN + NaNi 4.2235 - 0.1430i -2.0146 +
2.2094i
-1.0137 - 2.6399i -3.2754 - 1.3819i 4.2235 - 0.1430i -3.2754 -
1.3819i

Columns 5 through 6

-0.1540 - 2.4368i 1.6118 + 1.3688i
-1.0137 - 2.6399i 2.3129 - 0.5534i

Gav(:,:,3) =

1.0e+036 *

Columns 1 through 4

-3.2754 - 1.3819i 4.2235 - 0.1430i -3.2754 - 1.3819i -1.0137 -
2.6399i
-2.0146 + 2.2094i 4.2235 - 0.1430i NaN + NaNi 4.2235 -
0.1430i

Columns 5 through 6

2.3129 - 0.5534i -0.4026 + 2.0435i
-2.0146 + 2.2094i -0.1540 - 2.4368i

Gav(:,:,4) =

1.0e+036 *

Columns 1 through 4

-1.0137 - 2.6399i -2.0146 + 2.2094i -1.0137 - 2.6399i -2.5135 -
0.0715i
-1.0137 - 2.6399i -3.2754 - 1.3819i 4.2235 - 0.1430i -3.2754 -
1.3819i

Columns 5 through 6

-2.0102 - 0.9590i 0.1236 - 1.9961i
-1.0137 - 2.6399i 2.3129 - 0.5534i

Gav(:,:,5) =

1.0e+036 *

Columns 1 through 4

2.3129 - 0.5534i -0.1540 - 2.4368i 2.3129 - 0.5534i -2.0102 -
0.9590i
-2.5135 - 0.0715i -1.0137 - 2.6399i -2.0146 + 2.2094i -1.0137 -
2.6399i

Columns 5 through 6

-1.9317 + 0.6959i -1.8819 + 0.1889i
-2.5135 - 0.0715i -2.0102 - 0.9590i

Gav(:,:,6) =

1.0e+036 *

Columns 1 through 4

-0.4026 + 2.0435i 1.6118 + 1.3688i -0.4026 + 2.0435i 0.1236 -
1.9961i
-2.0102 - 0.9590i 2.3129 - 0.5534i -0.1540 - 2.4368i 2.3129 -
0.5534i

Columns 5 through 6

-1.8819 + 0.1889i -1.3358 + 1.1737i
-2.0102 - 0.9590i -1.9317 + 0.6959i

Gav(:,:,1) =

1.0e+036 *

Columns 1 through 4

-3.2754 - 1.3819i 4.2235 - 0.1430i -3.2754 - 1.3819i -1.0137 -
2.6399i
-2.5135 - 0.0715i -1.0137 - 2.6399i -2.0146 + 2.2094i -1.0137 -
2.6399i
-1.9317 + 0.6959i -2.0102 - 0.9590i 2.3129 - 0.5534i -0.1540 -
2.4368i

Columns 5 through 6

2.3129 - 0.5534i -0.4026 + 2.0435i
-2.5135 - 0.0715i -2.0102 - 0.9590i
2.3129 - 0.5534i -2.0102 - 0.9590i

Gav(:,:,2) =

1.0e+036 *

Columns 1 through 4

4.2235 - 0.1430i NaN + NaNi 4.2235 - 0.1430i -2.0146 +
2.2094i
-1.0137 - 2.6399i -3.2754 - 1.3819i 4.2235 - 0.1430i -3.2754 -
1.3819i
-2.0102 - 0.9590i -2.5135 - 0.0715i -1.0137 - 2.6399i -2.0146 +
2.2094i

Columns 5 through 6

-0.1540 - 2.4368i 1.6118 + 1.3688i
-1.0137 - 2.6399i 2.3129 - 0.5534i
-1.0137 - 2.6399i -2.5135 - 0.0715i

Gav(:,:,3) =

1.0e+036 *

Columns 1 through 4

-3.2754 - 1.3819i 4.2235 - 0.1430i -3.2754 - 1.3819i -1.0137 -
2.6399i
-2.0146 + 2.2094i 4.2235 - 0.1430i NaN + NaNi 4.2235 -
0.1430i
2.3129 - 0.5534i -1.0137 - 2.6399i -3.2754 - 1.3819i 4.2235 -
0.1430i

Columns 5 through 6

2.3129 - 0.5534i -0.4026 + 2.0435i
-2.0146 + 2.2094i -0.1540 - 2.4368i
-3.2754 - 1.3819i -1.0137 - 2.6399i

Gav(:,:,4) =

1.0e+036 *

Columns 1 through 4

-1.0137 - 2.6399i -2.0146 + 2.2094i -1.0137 - 2.6399i -2.5135 -
0.0715i
-1.0137 - 2.6399i -3.2754 - 1.3819i 4.2235 - 0.1430i -3.2754 -
1.3819i
-0.1540 - 2.4368i -2.0146 + 2.2094i 4.2235 - 0.1430i NaN +
NaNi

Columns 5 through 6

-2.0102 - 0.9590i 0.1236 - 1.9961i
-1.0137 - 2.6399i 2.3129 - 0.5534i
4.2235 - 0.1430i -2.0146 + 2.2094i

Gav(:,:,5) =

1.0e+036 *

Columns 1 through 4

2.3129 - 0.5534i -0.1540 - 2.4368i 2.3129 - 0.5534i -2.0102 -
0.9590i
-2.5135 - 0.0715i -1.0137 - 2.6399i -2.0146 + 2.2094i -1.0137 -
2.6399i
2.3129 - 0.5534i -1.0137 - 2.6399i -3.2754 - 1.3819i 4.2235 -
0.1430i

Columns 5 through 6

-1.9317 + 0.6959i -1.8819 + 0.1889i
-2.5135 - 0.0715i -2.0102 - 0.9590i
-3.2754 - 1.3819i -1.0137 - 2.6399i

Gav(:,:,6) =

1.0e+036 *

Columns 1 through 4

-0.4026 + 2.0435i 1.6118 + 1.3688i -0.4026 + 2.0435i 0.1236 -
1.9961i
-2.0102 - 0.9590i 2.3129 - 0.5534i -0.1540 - 2.4368i 2.3129 -
0.5534i
-2.0102 - 0.9590i -2.5135 - 0.0715i -1.0137 - 2.6399i -2.0146 +
2.2094i

Columns 5 through 6

-1.8819 + 0.1889i -1.3358 + 1.1737i
-2.0102 - 0.9590i -1.9317 + 0.6959i
-1.0137 - 2.6399i -2.5135 - 0.0715i

***********************************************************
Roger Stafford wrote:


In article <ef4feb7.-1@xxxxxxxxxxxxxxxxxxxxxxx>, vioravis
<vioravis@xxxxxxxxxxxxxxxx> wrote:

I have the following MATLAB code:

for i=1:N;
Av(i,:,:)=i*m*h; % This is actually a complex equ
end;

Av(i,:,:)

N has been defined as 3.

The result I obtained is given below. Av has been generated 6
times (
I am not sure why 6)

..... (Display of Av(i,:,:)?) .......

Can someone help me understand this result? Thanks.
------------------
Right after

for i=1:N;
Av(i,:,:)=i*m*h;
end;

you appear to have typed:

Av(i,:,:).

If so, this would be the same as typing

Av(3,:,:)

since 3 was the last value assumed by the 'i' variable in the
for-loop.
What follows then would be a display of

Av(3,:,:) = 3*m*h,

so it would appear that m*h is a 6 by 6 matrix. The form of this
display
is apparently affected by the fact that matlab is aware that 'Av'
is a
three-dimensional matrix even though the first index is restricted
to 3.
(I say "apparently" because my own matlab version (4a) does not
permit 3D
arrays, and I cannot be certain of the display format.)

One bit of advice: When you are dealing with complex quantities,
it is
inadvisable to use the symbol 'i' as an index since it could easily
be
confused as the imaginary value, i = sqrt(-1). Use some other
symbol such
as 'ix' or 'k'.

Roger Stafford

.



Relevant Pages

  • Re: how to terminate image displaying in GUI
    ... another in a certain time interval (for loop is used to achieve ... displaying, the other one is "stop" to terminate display. ... What other command can I use instead? ... MATLAB file exchange: http://www.mathworks.com/matlabcentral/fileexchange ...
    (comp.soft-sys.matlab)
  • Re: importing files sequentially in matlab
    ... Can someone please tell me a way that matlab can Import each file sequentially and display that fft of each file. ... end loop? ...
    (comp.soft-sys.matlab)
  • disp(...) prints with delay
    ... When I use "disp" function to display something in the screen it is ... displayed after a long time (actually after the end of a long loop ... Note: I use Matlab 7.0 ...
    (comp.soft-sys.matlab)
  • Re: Matlab keeps timing out when I use it to control a webcam
    ... I am using Matlab to control a webcam that takes images ... are nestled in a while loop, so that with each loop of the ... The webcam is a Philips SPC1000NC. ... are getting an even frame rate which would help standardize ...
    (comp.soft-sys.matlab)
  • Re: Mathematica Vs. Matlab
    ... The general DO loop in Macsyma is designed to handle cases where the loop ... Do either Matlab or ... >> number of other software packages. ... >> both Mathematica and MATLAB in the two years since the report was last ...
    (sci.math.symbolic)