Student Support Forum: 'Problem with a function with two parameters' topicStudent Support Forum > General > Archives > "Problem with a function with two parameters"

 Next Comment > Help | Reply To Topic
 Author Comment/Response Joel Santos 05/28/08 03:05am Hello! I want to make an IF expression that chooses from the elements in two matrixes. So, if an element of matrixa is different from 0, then returns that element, and if not, returns the element in the same position in matrixb Here are the matrixes: matrixa = {{0, 1, 0, 2}, {0, 0, 1, 1}}; matrixb = {{a, b, c, d}, {a, b, c, d}}; and what I want to get would be result={{a,1,c,2},{a,b,1,1}} If I use only one parameter, it works (for example, changing #2 with a constant). But I can't make it work with two variables. Can you help me? What's wrong in this statement? I suppose that is the brackets thing [], that confuses the Map function, but if I use the keys {}, then the if don't find the two variables... Map[If[#1 != 0, #1, #2]&,[matrixa, matrixb], {2}] Thanks in advice URL: ,

 Subject (listing for 'Problem with a function with two parameters') Author Date Posted Problem with a function with two parameters Joel Santos 05/28/08 03:05am Re: Problem with a function with two parameters Xavier 05/29/08 1:26pm Re: Problem with a function with two parameters Randy Silvers 05/29/08 8:08pm Re: Problem with a function with two parameters yehuda ben-s... 05/30/08 06:14am Re: Problem with a function with two parameters Joel Santos 06/03/08 09:52am
 Next Comment > Help | Reply To Topic