Effacer les filtres
Effacer les filtres

how to fill matrix?

7 vues (au cours des 30 derniers jours)
Mira le
Mira le le 15 Août 2021
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.

Réponse acceptée

Awais Saeed
Awais Saeed le 15 Août 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

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by