How do I keep it running if there was any error

Here is the simplified code:

for k=1:1:50
variable x
minimize f(x+c(k))
subject to

The code is just a sample to describe my problem. Now I want to know if in the k_th loop, the program will report an error when the problem was not successfiully solved ,because the problem itself has no solution. Now I want to skip the errors and let the program continue and return a NaN value to get my emulated image. I used the ‘try’ function to try it but It’s not feasible.Please give me some advice ,thanks .

Does this so what you want? Detecting of returning error in CVX

Note that a CVX error, as try catch is designed to catch. is different than an infeasible problem for which CVX will populate CVX variables with NaN. The approach in my link deals with CVX errors, such as not being DCP-compliant due to input data making a problem instance non-convex.

Thank you Mark, it’s good helpful to me.