現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
Hello All,
I am trying to create a S function in matlab which will read data from a video file and send the frame data via the output port.
The each and every frame information is read using a thread (External framework thread invoked through c++)and the information is sent to in the output pin using mdlOutputs.
The S function I created starts the read thread in mdlStart, but the mdlOutputs is called only after the read thread is stopped. hence mdlOutputs give me only the last frame information for every simulation time step.
I would like to know if it is possible to explicitly invoke mdlOutputs from read thread to receive the each and every frame information.
Thank you very much.
Please suggest if Multithreading is possible with S functions.
Regards Sarfraaz
採用された回答
Kaustubha Govind
2011 年 4 月 5 日
mdlOutputs must be invoked by the Simulink engine, because it needs the current SimStruct passed in. It is never advisable to call S-function call-back methods from another callback method.
mdlStart is called only once during model execution (at the beginning), whereas mdlOutputs is called at every time step - it seems like you should really be doing your reading in mdlOutputs directly, and not in mdlStart. Is there a reason you chose your current workflow?
14 件のコメント
Sarfraaz
2011 年 4 月 6 日
Hello Mr. Govind,
The reading of the frames is done using an external framework invoked from the sfunction. It runs as a separate thread and i need to send the frame information through the output port. Is there a any work around??
i tried copying the simstruct in a global variable and tried to invoke mdlOutputs but it doesn't work. is there any event that could be fired to invoke mdlOutputs explicitly ?
Kaustubha Govind
2011 年 4 月 6 日
I'm sorry, but I still don't understand why you don't call this external framework from mdlOutputs directly. That seems like the right way to go in your case.
Sarfraaz
2011 年 4 月 6 日
Even if i call the external framework from mdlOutputs the external framework will run has a separate thread and extract the frame information. I need to find a way to update the output port from the other thread. so that i get information about all the frames.
Kaustubha Govind
2011 年 4 月 6 日
Is there no way to aggregate the data read by the threads and pass them all together back to the S-function? Note that it is not safe to call any MATLAB API functions (mdlOutputs and any SimStruct-related functions included) from a thread - you must also call them from the main process that spawns the threads.
Sarfraaz
2011 年 4 月 7 日
Thanks for the suggestion. I have synchronized the operation between my thread and MATLAB thread.
I am still stuck in the step where is should terminate the MATLAB thread when my other thread ends before the end of simulation time. IS it possible to call mdlTerminate once my other thread is terminated??
Kaustubha Govind
2011 年 4 月 7 日
You must leave all invocations to S-function callback methods (like mdlTerminate) to the Simulink engine. Could you please elaborate on what you do in this "MATLAB thread"?
Sarfraaz
2011 年 4 月 7 日
Most of the computation is done in my thread. MaATLAB thread only initializes the arrays, starts the other thread and updates the output port.
I want to stop the MATLAB thread once my other thread is terminated. If not the data from the last frame read by my thread is given out as output for every simulation step.
Kaustubha Govind
2011 年 4 月 7 日
So would you like to read all the frames only once and send out multiple frames at every time step? It seems like the right thing to do would be to process one frame at a time (so the last frame read by your thread is the latest one to be processed).
Sarfraaz
2011 年 4 月 8 日
I need to process one frame at a time, but I want to stop the simulation once end of video file is reached.
Sarfraaz
2011 年 4 月 8 日
It would also be nice if you tell me how to handle simulink pause in Sfunction
Kaustubha Govind
2011 年 4 月 8 日
I don't know of a way to stop the simulation from the S-function directly, but you can use the Stop Simulation block (http://www.mathworks.com/help/toolbox/simulink/slref/stopsimulation.html) in your model to do this. You can output a non-zero valued signal from the S-function when you want to stop the simulation and connect that signal to the Stop Simulation block. HTH!
Sarfraaz
2011 年 4 月 8 日
Thank you very much. How to handle pause? I dont see any callback function for pause.
Kaustubha Govind
2011 年 4 月 8 日
The above doc page has a link titled "Creating Pause Blocks": http://www.mathworks.com/help/toolbox/simulink/ug/f11-31373.html#bq0ht63
Sarfraaz
2011 年 4 月 11 日
Thank you very much.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Simulink Coder についてさらに検索
製品
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
