Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: how can I avoid for cycle in this snippet
Posted:
Nov 29, 2009 1:07 PM
|
|
thanks very much!!
"asd def" <lovlovlov@indiatimes.com> wrote in message <heucdv$9qm$1@fred.mathworks.com>... > here you go ...This works....just inspect into how function norm works !! > > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% > U = [1 2 3; 4 5 6; 7 8 9 ; 10 11 12]; > U = U./(repmat( (sum(abs(U(:,1:size(U,2))).^2).^(1./2)) , [size(U,1) 1])); > U % Answer > % 0.077615052570633 0.136717185404933 0.182574185835055 > % 0.310460210282533 0.341792963512332 0.365148371670111 > % 0.543305367994433 0.546868741619731 0.547722557505166 > % 0.776150525706333 0.751944519727130 0.730296743340222 > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% > > % SAME AS YOUR FOR LOOP SOLUTION > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% > U = [1 2 3; 4 5 6; 7 8 9 ; 10 11 12]; > U = [1 2 3; 4 5 6; 7 8 9 ; 10 11 12]; > for i = 1:size(U,2), > U(:,i) = U(:,i) / norm(U(:,i),2); > end > U % Answer > % 0.077615052570633 0.136717185404933 0.182574185835055 > % 0.310460210282533 0.341792963512332 0.365148371670111 > % 0.543305367994433 0.546868741619731 0.547722557505166 > % 0.776150525706333 0.751944519727130 0.730296743340222 > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|