I am to create a function that replaces columns 'm' through till 'n' with zeros. Here is what I have so far:
zeroColumns[mat_, m_ ;; n_] := ReplacePart[mat, {_, m | n} -> 0]
list1 = {{1, 2, 3, 4, 4}, {4, 5, 6, 9, 5}, {7, 3, 8, 9, 5}, {14, 3, 1,5, 6}}
zeroColumns[list1, 1 ;; 3]
which returns
{{1, 2, 3, 4, 4}, {4, 5, 6, 9, 5}, {7, 3, 8, 9, 5}, {14, 3, 1, 5, 6}} {{0, 2, 0, 4, 4}, {0, 5, 0, 9, 5}, {0, 3, 0, 9, 5}, {0, 3, 0, 5, 6}}
and that's not a surprise to me because in the part ReplacePart[list1, {_, m | n} -> 0]
I'm not going from 'm' to 'n'; instead, I'm choosing column 'm' and column 'n'. I tried replacing |
with ;;
but it does nothing. How can I iterate from 'm' to 'n' instead of just picking both? I cannot use loops. I'm not really interested in revamping my code. I'm sure there's just a simple way of altering the |
so that it goes through EVERY column instead of just THOSE two.