Re: Interpreting the colon operator
- From: vioravis <vioravis@xxxxxxxxxxxxxxxx>
- Date: Thu, 8 Mar 2007 19:05:06 -0500
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:times (
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
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
- Follow-Ups:
- Re: Interpreting the colon operator
- From: Roger Stafford
- Re: Interpreting the colon operator
- From: us
- Re: Interpreting the colon operator
- References:
- Interpreting the colon operator
- From: vioravis
- Re: Interpreting the colon operator
- From: Roger Stafford
- Interpreting the colon operator
- Prev by Date: Re: how to save a file as tif with a generated filename
- Next by Date: Re: Solving ODE's with ODE45
- Previous by thread: Re: Interpreting the colon operator
- Next by thread: Re: Interpreting the colon operator
- Index(es):
Relevant Pages
|