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)
Gaurav Srivastava on 4 Jun 2019
Commented: Walter Roberson on 31 Oct 2021
Given a Matrix A, Create a row vector of 1's that has same number of elements as A has rows. Create a column vector of 1's that has the same number of elements as A has columns. Using matrix multiplication, assign the product of the row vector, the matrix A, and the column vector (in this order) to the variable result. A = [1:5; 6:10; 11:15; 16:20];
5 CommentsShowHide 4 older comments
Walter Roberson on 31 Oct 2021 at 8:17
That does not appear to be an answer to the question that was asked?

Sign in to comment.

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 CommentsShowHide 5 older comments
Habib Ali on 19 Jan 2021
A = [1:5; 6:10; 11:15; 16:20];
r=[1 1 1 1]
y=[1;1;1;1;1]
result=r*A*y

Sign in to comment.

More Answers (17)

Alex Mcaulley on 4 Jun 2019
I think the goal of this forum is not to do anyone's homework, but to solve generic questions about Matlab that can help more users. This exercise is very simple, anyone who has ever used Matlab could do it, so, I think the best thing we can do is help @Gaurav to know how to learn the basics of Matlab.
2 CommentsShowHide 1 older comment
Walter Roberson on 19 Apr 2021
ones(1,size(A, 1))

Sign in to comment.

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 CommentsShowHide 2 older comments
Avishkar patel on 30 Aug 2020
X=[1 1 1 1]
Y=[1;1;1;1;1]
result=X*A*Y

Sign in to comment.

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 CommentsShowHide -1 older comments

Sign in to comment.

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 CommentsShowHide 2 older comments
Aadesh Navade on 29 May 2020
remove that colon(;) from the last line

Sign in to comment.

Tushar Parmar on 11 May 2020
A = [1:5; 6:10; 11:15; 16:20]
B(1:4)=1;
f=B*A
C(1:5)=1;
C=C'
result=f*C
5 CommentsShowHide 4 older comments
Tharindu Priyankara on 29 Aug 2020
THANKS

Sign in to comment.

Gaurav Saini on 16 May 2020

given matrix A create a row vector of 1's that has some number of elements as A has rows in matlab programming

1 CommentShowHide None
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.

Sign in to comment.

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 CommentsShowHide -1 older comments

Sign in to comment.

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 CommentsShowHide -1 older comments

Sign in to comment.

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 CommentsShowHide -1 older comments

Sign in to comment.

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 CommentShowHide None
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]'?

Sign in to comment.

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 CommentsShowHide -1 older comments

Sign in to comment.

Razieh Gholami on 23 Dec 2020
Determine the elements of A^T, Adj A, A^−1
A =
1 2 1
2 1 0
−1 0 1
1 CommentShowHide None

Sign in to comment.

Mona Nasser on 9 Mar 2021
Consider the following MATLAB program: x = [ 1 2 ]; y = [ 3 4 ]; z = [ x [ y ; y ] ]; What is the value of z after this program executes?
1 CommentShowHide None

Sign in to comment.

Zyad Alhazme on 27 Mar 2021
Generate 2 vectors, say A and B; of the same length and add them. Then subtract them
1 CommentShowHide None

Sign in to comment.

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
1 CommentShowHide None

Sign in to comment.

samkit jain on 8 Apr 2021
Sir, MATLAB ( Ann toolbox) ke jariye kya hum data ko predict KR skte h kya ... Ye Dekh Kar bta do yarr Hume Thora Man lo hamare pass 2000 s lekar 2020 Ka data h Kisi bhi cheez Ka aur 2021 s 2025 tk Ka kya values aayega ye pta KR skte h kya usse
4 CommentsShowHide 3 older comments
Walter Roberson on 9 Apr 2021
You can predict it using something like NARX. I already posted the link.

Sign in to comment.

Javeria Riaz on 5 Jul 2021
Generate column vector for the first thirty natural numbers
1 CommentShowHide None
Walter Roberson on 5 Jul 2021
randperm(30).'

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!