# List Manipulation matrices

I have the following two lists:

List A:

A={{-0.0390625, 0., 0., 0., 0.0390625}, {-0.174377, -0.073478,
3.0893*10^-16, 0.073478,
0.174377}, {-0.196939, -0.112309, -1.50053*10^-16, 0.112309,
0.196939}, {-0.174377, -0.073478, 5.52991*10^-16, 0.073478,
0.174377}, {-0.0390625, 0., 0., 0., 0.0390625}}


List B:

B={{5, 6, 6, 5, 5}, {5, 5, 1, 5, 5}, {5, 4, 3, 4, 5}, {5, 5, 5, 5,
5}, {5, 0, 5,6, 5}}


I want to create 6 (max. value in list B) copies of List A, but if a value at point {i,j} in List B is smaller then 6, by example value X at point {i,j} in List B, then the value at point {i,j} in List A should only be used in the first X copies. Hence the last 6-X copie(s) should be zero at point {i,j}. How can I fix this?

-
If you show us your code so far, then we can try to fix it. – Yves Klett Oct 8 '13 at 14:37

Try this (for convenience, I use smaller matrices)

n = 3;
max = 4;
A = RandomReal[1.0, {n, n}];
(B = RandomInteger[{1, max}, {n, n}]) // MatrixForm


res = A UnitStep[B - #] & /@ Range@Max[B];
Column[MatrixForm /@ res]


-

ybeltukov's solution rules. Here's a different way to get the same result:

res = Table[
A Function[val, If[val <= i, 0, 1], Listable][B],
{i, Range[max] - 1}
];
Column[MatrixForm /@ res]

-

result=Transpose /@
MapThread[{#1, #2, #3, #4, #5} &,

Column[MatrixForm /@result]