From: dale on
Hi guys, I'm asking for some more help.I have a looping problem. My entire code is below.

I want to basically return M = [ 2049.7202; 3357.3591].

I only seem to return one of these depending on if I use:

% for i = 3:6
% for j = 10:11

OR

% for i = 8:9
% for j = 7:11



THE CODE:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
clear all;

M = zeros(1)


exts = [ 3 10 6 11;
8 7 9 11] % ext is the extends of the region


[ m n ] = size(exts) ;

len = m;



for i = exts(:,1): exts(:,3)
for j = exts(:,2): exts(:,4)

% for i = 3:6
% for j = 10:11
% for i = 8:9
% for j = 7:11


G= [ 0 0 0 0 0 0 0 0 0 0 0 0;
0 7.2111 17.2627 8.9443 10.7703 21.2603 3.1623 15.8114 1.4142 8.9443 7.2111 0;
0 11.4018 16.5529 134.6180 327.6126 417.4326 409.8902 393.2150 386.3315 306.7409 132.9662 0;
0 12.6491 5.8310 188.8597 323.3110 311.4643 398.8483 402.8399 396.3231 415.8654 317.5154 0;
0 16.4924 13.0384 130.2075 466.9047 341.5845 11.4018 22.8035 30.8869 384.8792 409.3531 0;
0 21.0238 12.6491 28.2843 422.1706 415.2036 6.3246 3.1623 16.1245 390.0051 415.0012 0;
0 27.8927 21.0238 17.2627 428.1682 410.1756 17.4929 7.6158 11.4018 391.1547 411.0304 0;
0 12.0000 30.8869 13.4164 342.8615 445.4773 401.0112 400.6045 414.0193 424.8670 326.4506 0;
0 6.3246 20.8806 11.3137 152.1184 324.5705 425.0012 421.2671 398.0050 318.2012 154.3826 0;
0 8.2462 8.6023 17.2047 17.0294 4.0000 24.2074 17.4929 13.0384 11.4018 9.0554 0;
0 5.0990 12.1655 4.2426 1.4142 11.3137 17.7200 11.4018 16.5529 8.2462 156.0833 0;
0 0 0 0 0 0 0 0 0 0 0 0];



L = [ 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 1 0;
0 0 0 0 0 0 0 0 0 0 1 0;
0 0 0 0 0 0 0 0 0 1 1 0;
0 0 0 0 0 0 0 0 0 1 1 0;
0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 2 2 2 2 0 0;
0 0 0 0 0 0 2 2 2 2 2 0;
0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0]

for k = 1:len
if (L(i,j) ==k)


M = M + G(i,j);

end

end
end
end

M
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

thanks
dale
From: Walter Roberson on
dale wrote:

> exts = [ 3 10 6 11;
> 8 7 9 11] % ext is the extends of the
> region

> for i = exts(:,1): exts(:,3)

exts(:,1) would be a column with 2 values, as would be exts(:,3). When you use
the colon operator (":") with multiple rows, it ignores all but the first row.
From: Andy on
for i = exts(:,1): exts(:,3)
for j = exts(:,2): exts(:,4)


Should be:

for i = exts(1,1): exts(1,3)
for j = exts(1,2): exts(1,4)
From: dale on
thanks andy , but it only returns the following:

M =

2049.7202

I would like to get:

M =

2049.7202
3357.3591

how can i do this?

best,
dale
From: Andy on
"dale " <persad34(a)gmail.com> wrote in message <i3f6bp$ccs$1(a)fred.mathworks.com>...
> thanks andy , but it only returns the following:
>
> M =
>
> 2049.7202
>
> I would like to get:
>
> M =
>
> 2049.7202
> 3357.3591
>
> how can i do this?
>
> best,
> dale

Well, look at your code. You simply overwrite M in every loop iteration, instead of storing a new value.