Call vensim
-
- Junior Member
- Posts: 4
- Joined: Wed Aug 04, 2010 11:20 am
Call vensim
I want to call Vensim from Matlab.For Example, For i=1:7 in matlab, I have to send i to vensim & run vensim & give the results in matlab & again for next i do again.
please help me.
please help me.
-
- Super Administrator
- Posts: 4603
- Joined: Wed Mar 05, 2003 3:10 am
-
- Junior Member
- Posts: 4
- Joined: Wed Aug 04, 2010 11:20 am
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
Just call the Vensim DLL - it looks like this should be pretty straightforward
http://www.mathworks.com/access/helpdes ... 43202.html
Then you can load and simulate a model, query the results and return the values for use in your Matlab routines.
http://www.mathworks.com/access/helpdes ... 43202.html
Then you can load and simulate a model, query the results and return the values for use in your Matlab routines.
-
- Junior Member
- Posts: 4
- Joined: Wed Aug 04, 2010 11:20 am
-
- Junior Member
- Posts: 4
- Joined: Wed Aug 04, 2010 11:20 am
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
That is exactly what I need to do.Then you can load and simulate a model, query the results and return the values for use in your Matlab routines.
Can anyone give me detailed instructions on how to do so?
I read through the link above, but didn't completely understand what I need to do explicitly.
Thank you very much for your help.
If you're familiar with a programming language, take a look at the examples in your Vensim dll folder (e.g. C:\Program Files\Vensim\dll ).
Tom
Tom
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
Yes, I already found that out. However, there are still syntactical mistakes when I try to call a Vensim function from Matlab. Example:
After loading the library into Matlab, I want to load a model. For invoking an external function from Matlab one has to use the 'calllib' function:
calllib('libname', 'funcname', arg1, ..., argN)
Here I chose vendll32 as libname and vensim_command as funcname. But I can't find the correct syntax to pass the input argument to the function (which could be SPECIAL>LOADMODEL, e.g.). I thougt that the command would have to look like
calllib('vendll32','vensim_command',special>loadmodel|rabfox.vpm),
but Matlab returns an error ('undefined function or variable 'SPECIAL'). If I use quotes around the argument, I get an error as well.
Neither the Vensim manual nor the mathworks.com page give an answer on how to call the function syntactically correct.
After loading the library into Matlab, I want to load a model. For invoking an external function from Matlab one has to use the 'calllib' function:
calllib('libname', 'funcname', arg1, ..., argN)
Here I chose vendll32 as libname and vensim_command as funcname. But I can't find the correct syntax to pass the input argument to the function (which could be SPECIAL>LOADMODEL, e.g.). I thougt that the command would have to look like
calllib('vendll32','vensim_command',special>loadmodel|rabfox.vpm),
but Matlab returns an error ('undefined function or variable 'SPECIAL'). If I use quotes around the argument, I get an error as well.
Neither the Vensim manual nor the mathworks.com page give an answer on how to call the function syntactically correct.
-
- Super Administrator
- Posts: 4603
- Joined: Wed Mar 05, 2003 3:10 am
A few suggestions/notes.
1. Have you experimented with the full name of the DLL?
2. The SPECIAL>LOADMODEL should have quotes around it.
The header file, does that contain the correct things?
I think in this instance you need to refer to Matlab support. The Vensim DLL uses a standard calling convention that is tested and works with lots of applications.
1. Have you experimented with the full name of the DLL?
2. The SPECIAL>LOADMODEL should have quotes around it.
The header file, does that contain the correct things?
I think in this instance you need to refer to Matlab support. The Vensim DLL uses a standard calling convention that is tested and works with lots of applications.
-
- Super Administrator
- Posts: 4603
- Joined: Wed Mar 05, 2003 3:10 am
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
Thanks for your help.
If you're asking whether I have tried to write 'vendll32.lib' instead of 'vendll32' - I have and it doesn't make a difference.
Concering the header file: Um, I have to admit that I was a bit insecure there, but first off the file vendll.h is the only header file in the dll folder. Second off: I thought that the file was okay since Matlab was able to display the loaded functions correctly.
There could be a mistake, though. Any ideas concering that?
Is there nobody who has called Vensim from Matlab himself? I'm quite sure that it isn't difficult at all, but one has to know the syntax.
I'm not sure what you mean by that. I know that the library has been loaded into Matlab; that part worked.Have you experimented with the full name of the DLL?
If you're asking whether I have tried to write 'vendll32.lib' instead of 'vendll32' - I have and it doesn't make a difference.
Also tried that. Still getting an error.The SPECIAL>LOADMODEL should have quotes around it.
Concering the header file: Um, I have to admit that I was a bit insecure there, but first off the file vendll.h is the only header file in the dll folder. Second off: I thought that the file was okay since Matlab was able to display the loaded functions correctly.
There could be a mistake, though. Any ideas concering that?
Is there nobody who has called Vensim from Matlab himself? I'm quite sure that it isn't difficult at all, but one has to know the syntax.
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
I posted my question in a matlab forum as well. This is a part of an answer I got:
"Without knowing the signature for the vensim_command function in that library, I don't think anyone is going to be able to give you any specific advice."
Well, that's more or less the problem I have. What is the exact signature of vensim_command? The manual says, "Command is a null terminated string that indicates the command to execute".
Would that be syntactically correct:
vensim_command("SPECIAL>LOADMODEL|modelname.mdl") ?
"Without knowing the signature for the vensim_command function in that library, I don't think anyone is going to be able to give you any specific advice."
Well, that's more or less the problem I have. What is the exact signature of vensim_command? The manual says, "Command is a null terminated string that indicates the command to execute".
Would that be syntactically correct:
vensim_command("SPECIAL>LOADMODEL|modelname.mdl") ?
Since Matlab can load and list the functions, I agree that the problem is not the header or dll name.
I think the next thing to try would be to see whether Vensim can call a function that takes only a numerical argument, like be_quiet. Matlab may require some particular argument to pass a string to Vensim.
Tom
I think the next thing to try would be to see whether Vensim can call a function that takes only a numerical argument, like be_quiet. Matlab may require some particular argument to pass a string to Vensim.
Tom
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
-
- Super Administrator
- Posts: 4603
- Joined: Wed Mar 05, 2003 3:10 am
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am