Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: how can I avoid for cycle in this snippet
Replies: 4   Last Post: Nov 29, 2009 1:07 PM

 Messages: [ Previous | Next ]
 Patrick Diviacco Posts: 23 Registered: 9/15/09
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]));
> % 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
> % 0.077615052570633 0.136717185404933 0.182574185835055
> % 0.310460210282533 0.341792963512332 0.365148371670111
> % 0.543305367994433 0.546868741619731 0.547722557505166
> % 0.776150525706333 0.751944519727130 0.730296743340222
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Date Subject Author
11/28/09 Patrick Diviacco
11/28/09 Basic Matlab User Puri
11/29/09 Patrick Diviacco
11/29/09 Basic Matlab User Puri
11/29/09 Patrick Diviacco