Home > Archive > Matlab > November 2005 > Simulink Help Needed
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Simulink Help Needed
|
|
| Teck Loonh 2005-11-28, 3:59 am |
| I am currently using simulink at the moment for my project. However,
I am have problems getting the values to refresh itself during the
course of running a simulink file. Eg. Input value to simulink
however, I want the simulink program to refresh the value whenever i
change the value outside simulink itself. Is this possible?
I would greatly appreciate if u can give me some advice. Thank you.
regards,
Teck Loong
| |
| teck loong 2005-11-29, 4:03 am |
| Teck Loonh wrote:
>
>
> I am currently using simulink at the moment for my project.
> However,
> I am have problems getting the values to refresh itself during the
> course of running a simulink file. Eg. Input value to simulink
> however, I want the simulink program to refresh the value whenever
> i
> change the value outside simulink itself. Is this possible?
>
> I would greatly appreciate if u can give me some advice. Thank you.
>
> regards,
> Teck Loong
can anyone pls help?
| |
|
| Hi Teck,
as far as I know you can use the simulation commands for Simulink.
% Get the handle of your Simulink-file:
sys=get_param('Name_of_my_Sim_file','han
dle');
% Get handle of the block you want to change:
h_lg1=find_system(sys,'FindAll','on','Na
me','My_Block_Name');
When your value change you have to set it with the following
commands:
set_param(h_lg1,'Value',27);
The last command is kind of tricky, because you have to figure out
which field of the block you want to change and what name this field
has.
I'm not sure if this works while the simulation is running, but it is
worth a try. The only ohter way that I can think of is to use
s-functions.
Tiga
| |
| teck loong 2005-11-29, 4:03 am |
| Tiga wrote:
>
>
> Hi Teck,
>
> as far as I know you can use the simulation commands for Simulink.
>
> % Get the handle of your Simulink-file:
> sys=get_param('Name_of_my_Sim_file','han
dle');
>
> % Get handle of the block you want to change:
> h_lg1=find_system(sys,'FindAll','on','Na
me','My_Block_Name');
>
> When your value change you have to set it with the following
> commands:
>
> set_param(h_lg1,'Value',27);
>
> The last command is kind of tricky, because you have to figure out
> which field of the block you want to change and what name this
> field
> has.
>
> I'm not sure if this works while the simulation is running, but it
> is
> worth a try. The only ohter way that I can think of is to use
> s-functions.
>
> Tiga
Thanks alot....
if i use the simulation commands, does this mean that the process is
not automated since i would have to type in the commands?
also, how do i use s-function to do this?
| |
|
| Hi Teck,
ok, I tried it in Simulink. The easiest way is to use the block
'MATLAB Fcn'. In the field 'MATLAB function' I entered:
get_my_var(u)
I connected a constant to this block, because it has to have an
input. I connected the output of the 'MATLAB Fcn' block to a display.
Then I wrote a function in the editor:
function Out = get_my_var(dummy)
% Simulink helper function. Just reads the
% variable 'MyVar' from the
% workspace and passes it to the output of the block.
Out = evalin('base','MyVar');
I saved this file as 'get_my_var.m'. Next I defined a variable
'MyVar' in the workspace.
MyVar = 55;
Then I started my Simulink file. When altered the value of 'MyVar' in
the workspace, it also changed in the Simulink file. That could be
monitored with the display. Gotcha!
This might not be the best or most elegant way, but it works. I hope
this will help you.
Tiga
| |
|
| Tiga wrote:
>
>
> Hi Teck,
>
> ok, I tried it in Simulink. The easiest way is to use the block
> 'MATLAB Fcn'. In the field 'MATLAB function' I entered:
>
> get_my_var(u)
>
> I connected a constant to this block, because it has to have an
> input. I connected the output of the 'MATLAB Fcn' block to a
> display.
>
> Then I wrote a function in the editor:
>
> function Out = get_my_var(dummy)
> % Simulink helper function. Just reads the
> % variable 'MyVar' from the
> % workspace and passes it to the output of the block.
> Out = evalin('base','MyVar');
>
> I saved this file as 'get_my_var.m'. Next I defined a variable
> 'MyVar' in the workspace.
>
> MyVar = 55;
>
> Then I started my Simulink file. When altered the value of 'MyVar'
> in
> the workspace, it also changed in the Simulink file. That could be
> monitored with the display. Gotcha!
>
> This might not be the best or most elegant way, but it works. I
> hope
> this will help you.
>
> Tiga
Hi Tiga...
Thank you so much... i really appreciate it...
| |
|
| Hi Tiga,
I tried using ur method and was able to write a simple program
successfully...
however, i tried using the same concept for my project application,
this method could not work. my project work requires the simulink
model to be compiled and run so that it will control voltage to move
an xytable using dSpace...
matlab.fcn is able to work in the normal context when we just run and
play the model but it is not so for my application.
I tried emailing you to thank you but the mail was rejected. could
you pls email me so that i can learn more from you? i really
appreciate your help and thank you
| |
|
| another point to add....
my application for the project uses rti. i guess thats the reason why
matlab.fcn cannot be used...
are there anyways to enable variable to change after compiling a rti
program?
|
|
|
|
|