Create a block to read keyboard inputs
29 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Raju Purohit
le 17 Juin 2011
Modifié(e) : John Kelly
le 26 Fév 2015
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???
0 commentaires
Réponse acceptée
Fangjun Jiang
le 17 Juin 2011
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 commentaires
Fangjun Jiang
le 21 Juin 2011
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.
Plus de réponses (1)
Kaustubha Govind
le 17 Juin 2011
Modifié(e) : John Kelly
le 26 Fév 2015
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 commentaires
Kaustubha Govind
le 21 Juin 2011
You can use eml.extrinsic to call functions unsupported for code generation.
Voir également
Catégories
En savoir plus sur Naming Conventions dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!