How can i insert a vector in a position into a matrix that already has values?

2 views (last 30 days)
Example: i have the matrix [2 5 1 2;4 2 1 3; 5 3 2 1; 6 3 2 1] and the vector [1 1 1 1] i want to insert the vector at row 2 the matriz will be [2 5 1 2; 1 1 1 1; 4 2 1 3; 5 3 2 1; 6 3 2 1] it is possible? i can do a implement, but if already have a command i'm grateful.

Accepted Answer

jonas
jonas on 12 Sep 2018
Edited: jonas on 12 Sep 2018
A is your matrix
B is your vector
out=[A(1,:);B;A(2:end,:)];

More Answers (1)

Matt J
Matt J on 12 Sep 2018
Edited: Matt J on 12 Sep 2018
A=[2 5 1 2;4 2 1 3; 5 3 2 1; 6 3 2 1];
clear B
B([1,3:5,2],:) = [A; [1 1 1 1] ]

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!