Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: vectorize a simple for loop?
Date: Fri, 11 Dec 2009 01:20:23 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 43
Message-ID: <hfs6om$bv5$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1260494423 12261 172.30.248.35 (11 Dec 2009 01:20:23 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 11 Dec 2009 01:20:23 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1326395
Xref: news.mathworks.com comp.soft-sys.matlab:591818

Does anyone know how to vectorize this simple for loop? 

% dum = [1 3; 1 4; 2 4]
dum =

     1     3
     1     4
     2     4

% Dij = zeros(size(dum,1),4)
Dij =

     0     0     0     0
     0     0     0     0
     0     0     0     0

for j=1:size(dum,1)
    for k = 1:size(dum,2)
        Dij(j,dum(j,k)) = 1;
    end
end

% Dij      
Dij =

     1     0     1     0
     1     0     0     1
     0     1     0     1

I think I want to use something like:
% Dij = zeros(size(dum,1),4);
% Dij(dum)=1

Dij =

     1     1     0     0
     1     0     0     0
     1     0     0     0

but obviously this does not work...

Thanks,
StevieP