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.

LiveLink, using a variable and for loop to change a parameter set

Please login with a confirmed email address before reporting spam

Hi all,

I would like to be able to change one parameter of my model inside of a for loop with LiveLink and then run the model. Does anyone know how to do this? My code looks something like this:

for CED=[1.0:0.01:3.0] model.param.set('C_ED', 'CED[mm]'); model.param.set('C_EP', '1[mm]'); model.param.set('C_EW', '0.5[mm]'); model.param.set('d_ci', '0.5[mm]'); model.param.set('d_nb', '0.4[mm]'); model.sol('sol1').runAll [b1,b2,b3,b4]=graphingfun(model); end

Thanks in advance!


2 Replies Last Post 13 mag 2019, 06:11 GMT-4

Please login with a confirmed email address before reporting spam

Posted: 6 years ago 11 mag 2019, 10:51 GMT-4

Hi John,

Why not using an auxiliary sweep?

If the above does not suit you, can you tell us how is the code you submitted not matching your expectations? I am using the java API rather than a LiveLink, so the syntax is slightly different, but from what I can read your code seems fine.

Hi John, Why not using an auxiliary sweep? If the above does not suit you, can you tell us how is the code you submitted not matching your expectations? I am using the java API rather than a LiveLink, so the syntax is slightly different, but from what I can read your code seems fine.

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 6 years ago 13 mag 2019, 06:11 GMT-4

Hi John

When you do

model.param.set('C_ED', 'CED[mm]');

Then the parameter 'C_ED' is set to the expression 'CED[mm]'. This doesn't transfer the value of the variable CED to Comsol. You need to do this instead:

model.param.set('C_ED', [num2str(CED) '[mm]']);
-------------------
Lars Gregersen
Comsol Denmark
Hi John When you do model.param.set('C_ED', 'CED[mm]'); Then the parameter 'C_ED' is set to the expression 'CED[mm]'. This doesn't transfer the value of the variable CED to Comsol. You need to do this instead: model.param.set('C_ED', [num2str(CED) '[mm]']);

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.