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

  • Home
  • SEARCH
  • 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 9123925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:27:22+00:00 2026-06-17T06:27:22+00:00

I have a matrix A and I want to multiply every row by 2

  • 0

I have a matrix A and I want to multiply every row by 2 using a for loop.

A = [1 2 3; 
     4 5 6; 
     7 8 9];

So essentially matlab should output:

[2  4  6; 
 8  10 12; 
 14 16 18];

I tried:

A = [1 2 3 ; 4 5 6  ; 7 8 9];
for i=1:3
    x= A([i],:)*2;
end 

but x outputs as [14 16 18].

How can I get my desired output?

  • 1 1 Answer
  • 0 Views
  • 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-06-17T06:27:23+00:00Added an answer on June 17, 2026 at 6:27 am

    With a for loop that will be:

    for n=1:size(A,1)
        x(n,:)=2*A(n,:);
    end
    

    But it is much easier to get the same result without a for loop:

    x=2*A;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so we have this matrix a=[1;2;3] and we want to multiply it by itself
I have one column matrix with n rows. I want difference between row 2
I have a vector v and a matrix M . I want to multiply
Hey! I have matrix class and i want to add, multiply and take transpose
I have a M x N matrix. I want to multiply each of the
I want to multiply two matrices but the triple loop has O(n 3 )
I have a Matlab application that generates a output matrix based on user input.
I have a matrix A which I want to convert into a data.frame of
I have a matrix A consisting of 200 vectors of size d. I want
I have this matrix of size 10000 by 1. I want to remove some

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.