Matrix generating