Replace certain columns of a matrix with 0?
20 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Walter Roberson
on 13 Oct 2015
A4 = A;
A4(:,5:end) = 0;
PS: we deal with MATLAB here, not with MathCad.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!