Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

How to debug MATLAB function (COMSOL 4)

Please login with a confirmed email address before reporting spam

I am able to declare MATLAB function in comsol.

When I run comsol, it gives me error "Incorrect size of returned vector. 596 elements were expected, but the returned matrix was 1 x 1"

The error is OK because my function returns only 1 number, because I am trying to debug it and look on parameters passed by COMSOL. I opened function in MATLAB editor and put breakpoint on it. But it never stops on breakpoint.

In COMSOL 3.5 this works (put breakpoint in MATLAB function).

Is there possibility to trace MATLAB functions?

6 Replies Last Post 20.04.2016, 18:07 GMT-4
COMSOL Moderator

Hello Jakub Zlamal

Your Discussion has gone 30 days without a reply. If you still need help with COMSOL and have an on-subscription license, please visit our Support Center for help.

If you do not hold an on-subscription license, you may find an answer in another Discussion or in the Knowledge Base.


Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 24.02.2011, 09:29 GMT-5
I have the same problem: I'm trying to set a breakpoint in a Matlab functiona that is being called by Comsol for debugging purposes.

any Idea on how to do that?
I have the same problem: I'm trying to set a breakpoint in a Matlab functiona that is being called by Comsol for debugging purposes. any Idea on how to do that?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 24.02.2011, 10:23 GMT-5
It is not possible to debug MATLAB function. (Only possibility is to write debug information in matlab function to file and look at it).

If You change function You must restart comsol to take changes into account or use clearfunction in MATLAB prompt

It is not possible to debug MATLAB function. (Only possibility is to write debug information in matlab function to file and look at it). If You change function You must restart comsol to take changes into account or use clearfunction in MATLAB prompt

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 05.11.2012, 10:36 GMT-5
My (dirty) solution:

function C = add(a,b)

fid = fopen('/home/user/log','w');
fprintf(fid,'display your debug log\n');
fclose(fid)

end

I use a file as debug log. It works but it's not an ideal solution...
My (dirty) solution: function C = add(a,b) fid = fopen('/home/user/log','w'); fprintf(fid,'display your debug log\n'); fclose(fid) end I use a file as debug log. It works but it's not an ideal solution...

Remi Magnard COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 07.11.2012, 04:52 GMT-5
If you are running COMSOL on Windows you can benefit of the MATLAB debugger.

What you need to do is:
1- Evaluate first the function so that a MATLAB process is started, for instance use the plot button in the function settings tab.
2- At the MATLAB prompt, that should have poped-up automatically to evaluate the function, type: desktop
3- You can now edit the function and add break point.
4- When running the model,the MATLAB debugger automatically stops at the break point and you can verify the intermediate value of the function variables.

This is also described in the LiveLink for MATLAB User's guide: Calling MATLAB function > The MATLAB Function Feature Node > Using the MATLAB Debugger (Windows only), (page 185 in the COMSOL 4.3a documentation)

Enjoy the modeling !
If you are running COMSOL on Windows you can benefit of the MATLAB debugger. What you need to do is: 1- Evaluate first the function so that a MATLAB process is started, for instance use the plot button in the function settings tab. 2- At the MATLAB prompt, that should have poped-up automatically to evaluate the function, type: desktop 3- You can now edit the function and add break point. 4- When running the model,the MATLAB debugger automatically stops at the break point and you can verify the intermediate value of the function variables. This is also described in the LiveLink for MATLAB User's guide: Calling MATLAB function > The MATLAB Function Feature Node > Using the MATLAB Debugger (Windows only), (page 185 in the COMSOL 4.3a documentation) Enjoy the modeling !

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 20.04.2016, 14:33 GMT-4
I've been searching for a solution to this problem as well. I followed the instructions provided, but when I click 'compute' to run my Comsol model, all of my breakpoints disappear in my matlab functions. Do I need to pass any sort of flag when I type desktop, that enables debugging? Or is this some sort of glitch?

For reference, I am using version 5.1

Thanks
I've been searching for a solution to this problem as well. I followed the instructions provided, but when I click 'compute' to run my Comsol model, all of my breakpoints disappear in my matlab functions. Do I need to pass any sort of flag when I type desktop, that enables debugging? Or is this some sort of glitch? For reference, I am using version 5.1 Thanks

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 20.04.2016, 18:07 GMT-4
In case anyone else is having problems, I discovered that if you have 'Clear functions automatically before solving' selected for your Matlab function, it resets all the breakpoints in that function prior to running. This box is useful if you have made any changes to your function since Comsol last used it, but is unnecessary otherwise. If this box is unchecked, you can proceed with debugging.
In case anyone else is having problems, I discovered that if you have 'Clear functions automatically before solving' selected for your Matlab function, it resets all the breakpoints in that function prior to running. This box is useful if you have made any changes to your function since Comsol last used it, but is unnecessary otherwise. If this box is unchecked, you can proceed with debugging.

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.