[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
remove for-loop from following code
From: |
Stefaan Himpe |
Subject: |
remove for-loop from following code |
Date: |
Sat, 05 Nov 2011 15:16:39 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.19) Gecko/20111010 Iceape/2.0.14 |
Hello all,
I have a question about optimizing my code.
I start from Y = [ 1 ; 3; 2 ]
I want to end up with Ytr = [ 1 0 0 0 ; 0 0 1 0 ; 0 1 0 0 ]
(so the number in Y indicates the column in which I want to see a one;
the number of elements in each row can is given in the following code as
a parameter D)
For now I do the following
function [Ytr] = ytransform(D, Y)
[rows, cols] = size(Y);
for row = 1:rows
Ytr(:,row) = (1:D == Y(row));
endfor
endfunction
Is there a way to do implement this without for loop over all rows of Y?
Best regards & thanks for this wonderful software.
Stefaan.
- remove for-loop from following code,
Stefaan Himpe <=
- Re: remove for-loop from following code, Juan Pablo Carbajal, 2011/11/06
- Re: remove for-loop from following code, Stefaan Himpe, 2011/11/06
- creation of a permutation matrix (WAS: Re: remove for-loop from following code), c., 2011/11/06
- Re: creation of a permutation matrix (WAS: Re: remove for-loop from following code), Carlo de Falco, 2011/11/06
- Re: creation of a permutation matrix (WAS: Re: remove for-loop from following code), Juan Pablo Carbajal, 2011/11/06
- Re: creation of a permutation matrix (WAS: Re: remove for-loop from following code), c., 2011/11/06