Inserting a column in a matrix before adding it to another matrix in a loop

2 views (last 30 days)
Hi all,
As the title says, I'm trying to insert a column in matrix B (B1, B2, B3) before adding it to matrix A to account for a column that already exists in matrix A.
Here's an example the vertical matrix that I have:
A =[1
2
3]
In this vertical matrix, I want to add matrices that are horizontal, but have it start at the second column. Like so:
%these are the matrices that will be added to A.
B1=[34 35 36 37];
B2=[48 49 30 21];
B3=[24 33 23 22];
%C is the final matrix that I want to have.
C=[1 34 35 36 37
2 48 49 30 21
3 24 33 23 22]
How do I add the horizontal matrices to the vertical matrix from the second column?

Answers (1)

James Tursa
James Tursa on 7 Oct 2020
Edited: James Tursa on 7 Oct 2020
C = [A,[B1;B2;B3]];

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!