Filter löschen
Filter löschen

What should I do to add a new row and a new column to a matrix?

5 Ansichten (letzte 30 Tage)
Just ad the title shows, I have a matrix, for example M with the size 3-by-4. The M is [1 2 3 4;5 6 7 8;1 2 3 4]
What should I do if i want to get another matrix ,N like that: [0 0 0 0 0 0; 0 1 2 3 4 0; 0 5 6 7 8 0; 0 1 2 3 4 0; 0 0 0 0 0 0];

Akzeptierte Antwort

Simon
Simon am 20 Sep. 2013
N = zeros(size(M)+2);
N(2:end-1, 2:end-1) = M;

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 20 Sep. 2013
Bearbeitet: Andrei Bobrov am 20 Sep. 2013
if you have Image Processing Toolbox
N = padarray(M,[1 1]);

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by