Create a block to read keyboard inputs

37 次查看(过去 30 天)
I want to create a block in simulink which prompts me to enter a key & reads ASCII values from keyboard while running a simulation. Input to the block is through keyboard & output is its ASCII value.
I think this can be done either in S-function or embedded matlab function blocks. But I dont know how to use these blocks.
Can someone help???

采纳的回答

Fangjun Jiang
Fangjun Jiang 2011-6-17
Drag and drop a Constant block, right click it, select "Block Properties ...", click the "Callbacks" tab, select "OpenFcn", type in the following line,
set(gcbh,'Value',num2str(double(input('Press a key: ','s'))));
Set your model simulation stop time to be inf and run the simulation, while the simulation is running, double click the Constant block, switch to Command window, press a key, observe the output value of the Constant block.
  2 个评论
Raju Purohit
Raju Purohit 2011-6-21
That was helpful to some extent. I am basically trying to model (3D model using VRML) a block which should move right when I press right arrow key, move up when i press up arrow key and so on. I need to continuously feed the input through keyboard.
Fangjun Jiang
Fangjun Jiang 2011-6-21
Then, a MATLAB Fcn block would do it. Type in double(input('press a key','s')); in it and run the simulation. Keep in mind though, that this will ask you for a key input every simulation step. I tried a simple example and the value output is right. Not sure how the rest of your model would work with it.

请先登录,再进行评论。

更多回答(1 个)

Kaustubha Govind
Kaustubha Govind 2011-6-17
编辑:John Kelly 2015-2-26
The Embedded MATLAB Fcn block should be sufficient for your purpose. You can use the input function to read inputs from the keyboard.
Here is an example using the Embedded MATLAB Block: Creating an Example Model That Uses a MATLAB Function Block.
  2 个评论
Raju Purohit
Raju Purohit 2011-6-21
Actually Embedded MATLAB Block does not support input function.
Kaustubha Govind
Kaustubha Govind 2011-6-21
You can use eml.extrinsic to call functions unsupported for code generation.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by