Problem 44446. Add a vector to a matrix
Given a matrix mat of size mXn and a row vector v of size 1Xs, return a matrix with m+1 rows that conatains mat over v. The number of columns is the larger between n and s.
If s>n, the matrix is padded with Inf.
If n>s, the vector is padded with -Inf.
Examples:
inputs:
mat = [1 2
3 4]
v = [5 6 7 8]
output:
comb = [1 2 Inf Inf
3 4 Inf Inf
5 6 7 8 ]
inputs:
mat = [1 2 3 4 5
6 7 8 9 10]
v = [11 12]
output:
comb = [1 2 3 4 5
6 7 8 9 10
11 12 -Inf -Inf -Inf]
Solution Stats
Problem Comments
-
1 Comment
David Verrelli
on 13 Dec 2017
I think "m*n" & "1*s" (or "m×n" & "1×s") may be clearer. I read "mXn" & "1Xs" firstly as variable names.
Solution Comments
Show commentsProblem Recent Solvers185
Suggested Problems
-
Find the longest sequence of 1's in a binary sequence.
6543 Solvers
-
Project Euler: Problem 10, Sum of Primes
2018 Solvers
-
Solving Quadratic Equations (Version 1)
501 Solvers
-
Test Problem; Create a 5x5 array containing all ones
395 Solvers
-
Matrix of almost all zeros, except for main diagonal
185 Solvers
More from this Author25
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!