COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

• Email
• Follow

```Can anyone vectorize this (as I can't)...  Also, any help understanding
how you worked it out would also be appreciated...  Thanks.
-Steve

M is NxN (and values are integers in range 0-8)
P is NxN (and values are integers in range 1-8)
-------------------------------------------------
H=zeros(N*8,N*8);
H_p_rev=H;

for n=1:N
for m=1:N
if M(m,n)~=0
H((8*m-M(m,n)+1):8*m,8*n-8+P(m,n))=1;
H_p_rev((8*m-M(m,n)+1):8*m,(8*n)+1-P(m,n))=1;
end
end
end

```
 0
Reply srm72499 (11) 3/17/2005 11:12:40 PM

See related articles to this posting

```Hi,

you can simply avoid to use the if condition :

for n=1:N
for m=1:N
H((8*m-M(m,n)+1):8*m,8*n-8+P(m,n))=(M(m,n)~=0);
H_p_rev((8*m-M(m,n)+1):8*m,(8*n)+1-P(m,n))=(M(m,n)~=0);
end
end

It's not vectorized but it should be faster.

J�r�me
```
 0
Reply dutmatlab (3796) 3/18/2005 7:26:35 AM

```Why did I say faster ?
I need to drink my second coffee :-x

J�r�me
```
 0
Reply dutmatlab (3796) 3/18/2005 7:31:27 AM

2 Replies
48 Views

Similar Articles

12/7/2013 4:53:42 AM
[PageSpeed]