Question: How do I put a conditional function in a Matrix definition?

Basically what I would like to do, which seems self-explanitory but is obviously not in the right language for maple is this (this is for a local M within a procedure where P is a matrix already defined).

TemplateMatrix:=proc(P) local M;
M:=Matrix(3, if P[i,j]=1 then (i,j)->x[i,j] else (i,j)-> P[i,j]);
M
end proc;

basically what i'm trying to do is turn P which is currently just a matrix of numbers into a matrix which has variables where the number 1 was previously an entry.
 

Please Wait...