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)
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 Comments

Sign in to comment.

Accepted Answer

Manali Gupta
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

Sign in to comment.

More Answers (17)

Alex Mcaulley
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 Comments

Sign in to comment.


Sudhanshu Rasal
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

Sign in to comment.


Khom Raj Thapa Magar
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

Arakala Gautham
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

Sign in to comment.


Tushar Parmar
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 Comments

Sign in to comment.


Gaurav Saini
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 Comment
Steven Lord
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.



Hardik Mittal
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

Sneham Shrikant Vaidya
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

VISHWA D
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
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.







samkit jain
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 Comments

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!