Replace certain columns of a matrix with 0?

20 views (last 30 days)
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!

Answers (1)

Walter Roberson
Walter Roberson on 13 Oct 2015
A4 = A;
A4(:,5:end) = 0;
PS: we deal with MATLAB here, not with MathCad.
  1 Comment
Justin Bolinger
Justin Bolinger on 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!

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!