How to write this expression in matlab ? p ^ q ^ r

4 visualizzazioni (ultimi 30 giorni)
Mohamad
Mohamad il 14 Ott 2013
Risposto: Jan il 14 Ott 2013
I do know that p ^ q is and(p,q) . But not sure what p q and r is
Thank you

Risposte (3)

Jos (10584)
Jos (10584) il 14 Ott 2013
p^q^r
p = true ; q = true ; r = false ;
tf = p && q && r
help and
  1 Commento
Mohamad
Mohamad il 14 Ott 2013
Well no cause I am looking to have a truth table of 1 and 0.

Accedi per commentare.


Walter Roberson
Walter Roberson il 14 Ott 2013
[P, Q, R] = ndgrid([0 1]);
truthtable = P & Q & R;
[P(:), Q(:), R(:), truthtable(:)] %display it

Jan
Jan il 14 Ott 2013
Or perhaps:
for p = [false, true]
for q = [false, true]
for r = [false, true]
result = p & q & r;
disp([p, q, r, result])
end
end
end
This is Walter's solution broken down to simple loops.

Categorie

Scopri di più su Functions in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by