| 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: , |
|