Mathematica: If statment for lists

  • Mathematica
  • Thread starter Sarah rob
  • Start date
  • #1
16
0

Main Question or Discussion Point

I want to create an If statment that states; if the elements in, list1>0 , true subtract list2, false keep value from list1 so that i
end up with ans: {0,2,5,4}
list1 = {0, 2, 8, 9}
list2 = {1, 0, 3, 5}
I dont know how to represent the elements in the lists so that my If statment works
 

Answers and Replies

  • #2
1,069
29
Excellent example showing input and output. That makes it much easier to provide correct help.

In[12]:=list1={0,2,8,9};list2={1,0,3,5};
f[x_,y_]:=If[x>0,x-y,x];
MapThread[f,{list1,list2}]

Out[15]={0,2,5,4}
 

Related Threads on Mathematica: If statment for lists

  • Last Post
Replies
4
Views
2K
Replies
2
Views
798
Replies
1
Views
2K
Replies
22
Views
2K
  • Last Post
Replies
3
Views
14K
  • Last Post
Replies
2
Views
7K
Replies
1
Views
2K
Replies
3
Views
15K
Replies
2
Views
4K
Replies
5
Views
4K
Top