Hi Ayush,
Thank you for your answer. I have tried what you have said and encountered some problems. For the objective function I am using a Simulink model not a matlab function. I have constructed the simulink model of the example you have given and it works fine. However, my original simulink model is a bit complex when I try to run it, some constants and fromworkspace blocks seems to be not getting the data from the matlab workspace, do you have any workarounds for this ?
Kind Regards