Your line of code has me confused
The comment says that you are removing zero entries from M. But M has been defined to be a cell array of strings as
What is the intent of the above assignment? Do you really mean for M to be a cell array of strings, or do you mean it to be a cell array of numbers?
Also, the line of code
will generate an error since P and Q do not have the compatible dimensions for matrix multiplication.
Use the debugger to step through the code and you will probably get a good idea as to what is going on. Always look at the variables to verify that they are (with respect to dimension, type, etc.) what you expect them to be.