Filter löschen
Filter löschen

how to fill matrix?

6 Ansichten (letzte 30 Tage)
Mira le
Mira le am 15 Aug. 2021
Beantwortet: Awais Saeed am 15 Aug. 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.

Akzeptierte Antwort

Awais Saeed
Awais Saeed am 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

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by