Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I've a list of lists,

tl = {{True, False, m12}, {False, m22, m33}, {m32, False, True}}

and each nested list has the same length, What is the proper way to replace the occurances of all m* values, i.e., m12, m22, etc., with a particular value say x.

All I want is this result

tl = {{True, False, x}, {False, x, x}, {x, False, True}}`

Any help will be appreciated.

share|improve this question
    
Is there anything other than True, False and m*? –  Kuba Jun 7 at 19:23
    
No there are only True, False or m* –  aark Jun 7 at 19:30

2 Answers 2

up vote 3 down vote accepted

One rather literal (string-based) interpretation of your question:

tl = {{True, False, m12}, {False, m22, m33}, {m32, False, True}};

tl /. s_ /; StringTake[ToString[s], 1] == "m" :> X

{{True, False, X}, {False, X, X}, {X, False, True}}

share|improve this answer
    
Thanks man what i needed –  aark Jun 7 at 19:34
tl = {{True, False, m12}, {False, m22, m33}, {m32, False, True}};

Replace[tl, Except[True | False] :> z, {2}]

(* {{True, False, z}, {False, z, z}, {z, False, True}} *)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.