Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 267437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:33:04+00:00 2026-05-11T23:33:04+00:00

I normalize a vector V in MATLAB as following: normalized_V = V/norm(V); however, is

  • 0

I normalize a vector V in MATLAB as following:

normalized_V = V/norm(V);

however, is it the most elegant (efficient) way to normalize a vector in MATLAB?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:33:04+00:00Added an answer on May 11, 2026 at 11:33 pm

    The original code you suggest is the best way.

    Matlab is extremely good at vectorized operations such as this, at least for large vectors.

    The built-in norm function is very fast. Here are some timing results:

    V = rand(10000000,1);
    % Run once
    tic; V1=V/norm(V); toc           % result:  0.228273s
    tic; V2=V/sqrt(sum(V.*V)); toc   % result:  0.325161s
    tic; V1=V/norm(V); toc           % result:  0.218892s
    

    V1 is calculated a second time here just to make sure there are no important cache penalties on the first call.

    Timing information here was produced with R2008a x64 on Windows.


    EDIT:

    Revised answer based on gnovice’s suggestions (see comments). Matrix math (barely) wins:

    clc; clear all;
    V = rand(1024*1024*32,1);
    N = 10;
    tic; for i=1:N, V1 = V/norm(V);         end; toc % 6.3 s
    tic; for i=1:N, V2 = V/sqrt(sum(V.*V)); end; toc % 9.3 s
    tic; for i=1:N, V3 = V/sqrt(V'*V);      end; toc % 6.2 s ***
    tic; for i=1:N, V4 = V/sqrt(sum(V.^2)); end; toc % 9.2 s
    tic; for i=1:N, V1=V/norm(V);           end; toc % 6.4 s
    

    IMHO, the difference between “norm(V)” and “sqrt(V’*V)” is small enough that for most programs, it’s best to go with the one that’s more clear. To me, “norm(V)” is clearer and easier to read, but “sqrt(V’*V)” is still idiomatic in Matlab.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to normalize whitespace characters (space, newline, tab) in a
Consider the following code: template <int dim> struct vec { vec normalize(); }; template
I have a list of numeric values. I may normalize the values if needed.
I have a large database of normalized order data that is becoming very slow
I have to maintain an old database which is not properly normalized. For instance
I am trying to stick to the practice of keeping the database normalized, but
I'm just wondering what the optimal solution is here. Say I have a normalized
I have a database that has lots of data and is all neat, normalized
I have designed database tables (normalised, on an MS SQL server) and created a
I have a new project which simply put, is an attempt to formalize the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.