How to associate M-File and Simulink?

11 visualizzazioni (ultimi 30 giorni)
Erçin
Erçin il 27 Dic 2011
I have to execute physic system with codes in progressing with time. I did that in an M-File(coordinates is working) but the other system which is connected with physic system is in Simulink. I couldn't associate M-File in progressing with time and Simulink. May i did that with sim command setting parameters?
My purpose is drawing an object with Simulink but object's coordinates is changing with time and this parameters calculating with M-File. How can i do that? Thank you for the answers now, sorry for bad english =/
  1 Commento
Erçin
Erçin il 27 Dic 2011
Is there anyway to pause and start function with sim command? I writed in a loop "sim" command and it is working but video display is blinking cause of starting-stoping simulation again and again. That is working start-stop mechanism, i need start-pause mechanism =)

Accedi per commentare.

Risposte (1)

Wayne King
Wayne King il 27 Dic 2011
Hi Ercin, You can use the MATLAB function block.
  3 Commenti
Kaustubha Govind
Kaustubha Govind il 29 Dic 2011
You can place the MATLAB Function block inside an Enabled Subsystem and control its execution using an enable signal.
The sim command only returns to MATLAB after the simulation is complete, so if you want to be able to pause simulation, you need to start simulation using set_param(bdroot,'SimulationCommand','start') so that control is immediately returned to MATLAB. You can then use the PAUSE command (say pause(5) if you want to run for 5secs) to let the model run for a short period, and then use set_param(bdroot,'SimulationCommand','pause') to pause simulation. Use set_param(bdroot,'SimulationCommand','stop') to stop simulation.
Erçin
Erçin il 30 Dic 2011
First of all; thank you for all replies...
1- I had defined variables with if conditions in Matlab Function and compiler said that undefined function or variable. Simulink is debugging regardless of looking if conditions and occuring despite defining initial conditions. Also if conditions which is in my matlab function doesnt work properly. I have to execute on Discrete Simulation type cause of video display. I think the problem is that.
2- I had tried pause and sim commands in M-File not in Matlab Function. Because pause is not working in Matlab Function, 'coder.extrinsic' doesnt solve the problem. When Matlab Function is reading all of the codes, simulation is automatically paused(doesnt mean it looks in pause mode).Depending on this; pause, timer or sim commands doesnt work properly in Matlab Function.
3- When I had defined my own enable system with all square wave or boolean variable, cause of not working properly if conditions in Matlab Function; it doesnt mean anything.
4- When i tried M-File, it gives me better solutions but i didnt manage to execute set_param(start,pause,continue etc) in for or while loop. it is interesting that set_param is working out of loop well.
5- I had composed the codes in Visual Basic 6. My way is adapting the codes to Matlab. I am trying to communicate Visual Basic with Matlab by creating Virtual Serial Port now. I tried send and receive datas in Visual Basic, this is working well but when i tried receiving datas with Simulink, the datas was going unconscious. That is being when Serial Receive block is changing data type. Trying different data types, gives me so different results. Any ideas?

Accedi per commentare.

Categorie

Scopri di più su General Applications in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by