Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.