Replace certain columns of a matrix with 0?

Let's say I define a 10x10 matrix (call it "A") and want to re-define a new matrix (call it "A4") that is the same as matrix "A" except only the original first 4 columns are kept... and the last 6 columns are replaced with zeros?
Basically, how I get from this:
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
to something like this?
1 2 3 4 0 0 0 0 0 0
1 2 3 4 0 0 0 0 0 0
1 2 3 4 0 0 0 0 0 0
1 2 3 4 0 0 0 0 0 0
1 2 3 4 0 0 0 0 0 0
1 2 3 4 0 0 0 0 0 0
1 2 3 4 0 0 0 0 0 0
1 2 3 4 0 0 0 0 0 0
1 2 3 4 0 0 0 0 0 0
1 2 3 4 0 0 0 0 0 0
Fairly new to Mathcad here, so thanks any help anyone can give!

Réponses (1)

A4 = A;
A4(:,5:end) = 0;
PS: we deal with MATLAB here, not with MathCad.

1 commentaire

Justin Bolinger
Justin Bolinger le 14 Oct 2015
Sorry, I'm a Chemical Engineer by education and we always used MathCAD. I got the names mixed up. Thanks so much for the help!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by