Generating energy gradient magnitude matrix