# Given a Matrix A, create a row vector of 1s that has same number of elements as A has rows

1,965 views (last 30 days)

Show older comments

##### 5 Comments

Walter Roberson
on 31 Oct 2021 at 8:17

That does not appear to be an answer to the question that was asked?

### Accepted Answer

Manali Gupta
on 20 May 2021

Edited: MathWorks Support Team
on 20 May 2021

R_vector = ones(1,size(A,1)); C_vector=ones(size(A,2),1); result = R_vector*A*C_vector;

##### 6 Comments

### More Answers (17)

Alex Mcaulley
on 4 Jun 2019

##### 2 Comments

Sudhanshu Rasal
on 5 May 2020

Edited: Sudhanshu Rasal
on 5 May 2020

Simple way to do this question is

X=[1 1 1 1]

Y=[1;1;1;1;1]

result=X*A*Y ????????

##### 3 Comments

Khom Raj Thapa Magar
on 28 Aug 2020

Given A = [1:5; 6:10; 11:15; 16:20];

row_vec = ones(1,size(A,1))

column_vec = ones(length(A),1)

result = row_vec * A * column_vec

Output:

row_vec =

1 1 1 1

column_vec =

1

1

1

1

1

result =

210

##### 0 Comments

Arakala Gautham
on 4 Apr 2020

R_vector = ones(1,size(A,1));

C_vector=ones(size(A,2),1);

result = R_vector*A*C_vector;

##### 3 Comments

Gaurav Saini
on 16 May 2020

##### 1 Comment

Steven Lord
on 16 May 2020

This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.

If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.

If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.

Rishabh Nirala
on 20 May 2020

A = [1:5; 6:10; 11:15; 16:20];

C = [1;1;1;1;1]

R = [1 1 1 1 ]

P = R * A

result = P*C

ANSWER = 210

##### 0 Comments

Hardik Mittal
on 26 May 2020

Input:

A = [1:5; 6:10; 11:15; 16:20]

B(1:4)=1;

D=B*A

C(1:5)=1;

C=C'

result=D*C

Solution

A =

1 2 3 4 5

6 7 8 9 10

11 12 13 14 15

16 17 18 19 20

f =

34 38 42 46 50

C =

1

1

1

1

1

result =

210

##### 0 Comments

Sneham Shrikant Vaidya
on 27 May 2020

A = [1:5; 6:10; 11:15; 16:20];

A

x = [1 1 1 1 ]

y = [1;1;1;1;1]

z = A*y

result =x*z

// you can also perform this way as we know z =(lxm)*(mxn) so we first multiply A*y as their inner dimension ara same

then we obtain result matrix z that has inner dimension equal to x so now we can multiply x*z to get final ans

##### 0 Comments

VISHWA D
on 22 Jun 2020

A = [1:5; 6:10; 11:15; 16:20];

row_vector=[1 1 1 1 1]

col_vector=[1; 1; 1; 1]

result=(row_vector*(A'))*(col_vector)

##### 1 Comment

lijuan wang
on 27 Aug 2020

I thought the assignment has a wrong requirement, right?

we should create a vector which has the some rows as A. So it should be row_vector=[1 1 1 1]'?

Aditya Tiwari
on 15 Sep 2020

R_vector = ones(1,size(A,1));

C_vector=ones(size(A,2),1);

result = R_vector*A*C_vector;

##### 0 Comments

Mona Nasser
on 9 Mar 2021

Zyad Alhazme
on 27 Mar 2021

Generate 2 vectors, say A and B; of the same length and add them. Then subtract them

qasim alsubayq
on 30 Mar 2021

Write a MATLAB program that computes the value of the Gaussian distribution N(m, S), at a given vector x where:

m=[0 1] T, s=[1 0; 0 1], x=[1 1] T

samkit jain
on 8 Apr 2021

##### 4 Comments

Walter Roberson
on 9 Apr 2021

You can predict it using something like NARX. I already posted the link.

### See Also

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!