Here is a list:
list = {{1, 2, 3, 2, 3}, {3, 1, 1, 2, 3}, {3, 2, 1, 3, 2}, {1, 2, 1, 1, 1}};
I wish to have all elements be zero except the first and the fourth in each row: desired:
list={{1, 0, 0, 2, 0}, {3, 0, 0, 2, 0}, {3, 0, 0, 3, 0}, {1, 0, 0, 1, 0}};
I have written:
Do[
Do[
If[Position[list, list[[i, j]]] != {i, 1} &&
Position[list, list[[i, j]]] != {i, 4}, list[[i, j]] = 0]
, {i, 1, 4}]
,{j, 1, 5}]
But it doesn't work correctly. Is there any way to reach this goal?
list[[All, {2, 3, 5}]] = 0
$\endgroup$ – MarcoB Jul 5 '17 at 18:16