Finally I gave chatGTP a try: "write a matlab function to generate Pauli matrices for an arbitrary spin number" Top, ChatGPT, bottom correct answer... not bad but the commutation relations are not right. Code length 20 lines vs 16 lines.