|
From: | Stefaan Himpe |
Subject: | Re: remove for-loop from following code |
Date: | Sun, 06 Nov 2011 09:52:16 +0100 |
User-agent: | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.19) Gecko/20111010 Iceape/2.0.14 |
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?
Try, N = lenth(Y); subs = [(1:N).' Y(:)]; Ytr = accumarray (subs, ones(N,1));
Hello, Thanks for your reply.After scanning the octave documentation once more I finally arrived at the following solution (which uses some special provisions to create permutation matrices):
function [Ytr] = ytransformed(K,Y) Ytr = eye(K)(Y',:); endfunction Thanks for your reply! Best regards, Stefaan.
[Prev in Thread] | Current Thread | [Next in Thread] |