how to fill matrix?
6 views (last 30 days)
Show older comments
Hello every one
I want to fill matrix with two vector like this:
first vector: 1 2 3 4 5
second vector 3 5 1 4
matrix is as follow:
1 2 3 4 5
3 0 1 1 0 0
5 1 1 0 0 1
1 0 1 0 1 0
4 0 1 1 0 1
How can I put both vectors in my matrix like this?, where the first cellule is empty
Thank you very much.
0 Comments
Accepted Answer
Awais Saeed
on 15 Aug 2021
I do not think that you can create such a matrix because there is a column dimension mis-match. You can add zero padding to get such a result
A = [1 2 3 4 5];
B = [3 5 1 4];
M = [0 1 1 0 0;1 1 0 0 1;0 1 0 1 0;0 1 1 0 1];
M = horzcat(B',M); % horizonal concatenation
% size(A,2) is not equal to size(M,2). To make them equal add zeros in A
M = vertcat([zeros(1,length(M)-length(A)) A],M) % vertical concatenation
0 Comments
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!