Add a vector to a matrix - MATLAB Cody - MATLAB Central

Problem 44446. Add a vector to a matrix

Difficulty:Rate

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

28.38% Correct | 71.62% Incorrect
Last Solution submitted on Apr 19, 2025

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
4
8
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Problem Recent Solvers183

Suggested Problems

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!