Path: news.mathworks.com!not-for-mail From: "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> Newsgroups: comp.soft-sys.matlab Subject: Re: How to make the function 'norm' treat its input as vectors? Date: Wed, 13 Oct 2010 15:03:03 +0000 (UTC) Organization: Universität Heidelberg Lines: 10 Message-ID: <i94hn7$kpl$1@fred.mathworks.com> References: <i938ok$smb$1@fred.mathworks.com> <i93kdo$o8f$1@fred.mathworks.com> <i94def$3h4$1@fred.mathworks.com> Reply-To: "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> NNTP-Posting-Host: webapp-03-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1286982183 21301 172.30.248.38 (13 Oct 2010 15:03:03 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Wed, 13 Oct 2010 15:03:03 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 869888 Xref: news.mathworks.com comp.soft-sys.matlab:678105 Dear Yang, I've created a C-Mex function for the 2-norm along a specific dimension. For [1 x 10000] vectors it is 20% faster than NORM, but for [1 x 100] vectors the overhead of calling the Mex eats up the performance, such that NORM is 35% faster than the C-Mex. Anyhow, for arrays allocating the memory for the x.*x array and the vector replied by SUM consumes a remarkable chunk of time, such that the C-mex, which calculates all values elementwise, is 20 to 50% faster than SQRT(SUM(x.*x)). If you are interested, I could publish it. But I'm still surprised, that such a common task is not solved by a built-in function. Kind regards, Jan