how to fill matrix?

10 次查看(过去 30 天)
Mira le
Mira le 2021-8-15
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.

采纳的回答

Awais Saeed
Awais Saeed 2021-8-15
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 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by