Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

problem creating a model using a Matlab function (Comsol 4)

Please login with a confirmed email address before reporting spam

Hi,
i want to create a Comsol model using a Matlab function like:

function myFunction()

model = ModelUtil.create('Model');
...

return

When i call the function Matlab returns this error:
??? Undefined variable "ModelUtil" or class "ModelUtil.create".

I guess somehow i have to tell Matlab to use Comsol 4 because it seems not able to find ModelUtil from within a function.
What am i doing wrong?

Thank you for any advice.

6 Replies Last Post 1 févr. 2012, 11:33 UTC−5

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 11 avr. 2011, 06:08 UTC−4
Just solved it - should have read the LiveLink-manual more carefully :) It is neccessary to import the Comsol classes first:

function myFunction()

import com.comsol.model.*
import com.comsol.model.util.*

model = ModelUtil.create('Model');
...

return



Just solved it - should have read the LiveLink-manual more carefully :) It is neccessary to import the Comsol classes first: function myFunction() import com.comsol.model.* import com.comsol.model.util.* model = ModelUtil.create('Model'); ... return

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 10 mai 2011, 17:36 UTC−4
Hey i ask the same

thanks for your answer tomorrow i'll try it too

i want to make my model in comsol as a function in matlab and then i do sort of parametric
sweep on this model by using a for loop calling my model function and always with sweeping parameter

thanks a lot
and you think your advices here will work for me too?

Best regards,
Arye
Hey i ask the same thanks for your answer tomorrow i'll try it too i want to make my model in comsol as a function in matlab and then i do sort of parametric sweep on this model by using a for loop calling my model function and always with sweeping parameter thanks a lot and you think your advices here will work for me too? Best regards, Arye

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 11 mai 2011, 13:35 UTC−4
Thanks it worked you are awesome
Thanks it worked you are awesome

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2 nov. 2011, 04:39 UTC−4
We need install LiveLink before using matlab combined with comsol v4?
We need install LiveLink before using matlab combined with comsol v4?

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2 nov. 2011, 05:30 UTC−4
Hi

Indeed you need a corresponding Matlab installed, then COMSOL With the Matlab livelink for V4 to get everything running together. Cehck with your local rep, or on the KB for install details

--
Good luck
Ivar
Hi Indeed you need a corresponding Matlab installed, then COMSOL With the Matlab livelink for V4 to get everything running together. Cehck with your local rep, or on the KB for install details -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 1 févr. 2012, 11:33 UTC−5
Hello,

As an addition to the explanation from "Chris Shor"; it is also possible to run a LiveLink operation to start model implamentation without creating a MATLAB function file. That was especially helpful (and seems faster) in my case, since I have pre-processing of my data before starting model implementation.

To do so;

..._______________________________________________

%% PRE_PROCESSING

% constants
x = 1;
y = 2;
z = 3;
...

%% MODEL IMPLEMENTATION

mphstart % connect MATLAB to the COMSOL server (in default port)
import com.comsol.model.* % import the COMSOL classes
import com.comsol.model.util.*

model = ModelUtil.create('Model'); % start model implementation
model.name('xxx');

model.param.set('x', [num2str(x) 'unit'], 'explanation'); % define global model parameters (constants)
model.param.set('y', [num2str(y) 'unit'], 'explanation');
model.param.set('z', [num2str(z) 'unit'], 'explanation');
....

return
..._______________________________________________


Hopefully that will be helpful.
(LiveLink for MATLAB Users Guide - p.12-14)


--
-----
COMSOL 4.2a
Ubuntu 11.04
MATLAB R2010a
Hello, As an addition to the explanation from "Chris Shor"; it is also possible to run a LiveLink operation to start model implamentation without creating a MATLAB function file. That was especially helpful (and seems faster) in my case, since I have pre-processing of my data before starting model implementation. To do so; ..._______________________________________________ %% PRE_PROCESSING % constants x = 1; y = 2; z = 3; ... %% MODEL IMPLEMENTATION mphstart % connect MATLAB to the COMSOL server (in default port) import com.comsol.model.* % import the COMSOL classes import com.comsol.model.util.* model = ModelUtil.create('Model'); % start model implementation model.name('xxx'); model.param.set('x', [num2str(x) 'unit'], 'explanation'); % define global model parameters (constants) model.param.set('y', [num2str(y) 'unit'], 'explanation'); model.param.set('z', [num2str(z) 'unit'], 'explanation'); .... return ..._______________________________________________ Hopefully that will be helpful. (LiveLink for MATLAB Users Guide - p.12-14) -- ----- COMSOL 4.2a Ubuntu 11.04 MATLAB R2010a

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.