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.

Create interpolation function using LiveLink with Matlab

Please login with a confirmed email address before reporting spam

Hi everyone,

I would like to create a user-defined interpolation function using LiveLink with Matlab.

Here is what I do (in Matlab):

model.component('comp1').func.create(int2, 'Interpolation'); model.component('comp1').func(int2).set('funcname','my_func'); model.component('comp1').func(int2).label('my_func_label'); model.component('comp1').func(int2).set('argunit', 's'); model.component('comp1').func(int2).set('fununit', 'Pa');

I know there are three methods to feed data to the interpolation function: Result table, file and local table. I would prefer to use the local table, so I do, which is very tedious:

model.component('comp1').func(int2).setIndex('table', t1, 1, 0); model.component('comp1').func(int2).setIndex('table', value1, 1, 1); model.component('comp1').func(int2).setIndex('table', t2, 2, 0); model.component('comp1').func(int2).setIndex('table', value2, 2, 1); model.component('comp1').func(int2).setIndex('table', t3, 3, 0); model.component('comp1').func(int2).setIndex('table', value3, 3, 1); ... ... The question: Is there a way to write the entire 2D-array or 2x1 vectors to the table? Since I need to do this for many interpolation functions (on the order of 100s) and for every time step in the simulation (on the order of 1000s), there will be a lot of resulting calls. Alternatively, I guess I could first write the data to files, but then I would have to create 100s of files first to read from.

Any help and suggestions would be appreciated,

Theo


1 Reply Last Post 22 mai 2020, 04:51 UTC−4
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 4 years ago 22 mai 2020, 04:51 UTC−4

Hi Theodor

Sure there is. It is even covererd by the documetation.

Find the section "Example: Curve Interpolation" in the LiveLink for Matlab User's Guide.

Hint: it is a single line of code!

-------------------
Lars Gregersen
Comsol Denmark
Hi Theodor Sure there is. It is even covererd by the documetation. Find the section "Example: Curve Interpolation" in the LiveLink for Matlab User's Guide. Hint: it is a single line of code!

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.