How to import an audio file to simulink from app designer

조회 수: 15 (최근 30일)
Roberto Lemaitre
Roberto Lemaitre 2021년 5월 23일
댓글: Roberto Lemaitre 2021년 5월 24일
Right now i can select an audio file from my pc from App Designer but i need to know how to use it on simulink. Something like the "To multimedia file" block:
Here's the code i use for playing the song at the moment from App Designer:
So basically i need to be able to use the audio file i select from app designer inside simulink and work with it from there. Thanks!

채택된 답변

jibrahim
jibrahim 2021년 5월 24일
Hi Roberto,
Maybe this answers your scenario: In your App designer code, once the user has selected the file, you can use set_param to set the FIlename parameter of a 'From Multimedia File' block to the selected name. You can then run your model and have access to the desired audio signal in Simulink
  댓글 수: 3
jibrahim
jibrahim 2021년 5월 24일
편집: jibrahim 2021년 5월 24일
Sure.
Let's say your model is called myModel.
Your model must be loaded or open (either works) before you can modify it. This code does it:
load_system('myModel') % The model will load, but does not open
open_system('myModel') % The model opens
You can execute this code outside your APP, or you can include this code in some initialization section, so that the model loads when you start using the APP.
Now let's say the 'From Multimedia File' block in your model is named myReader. To change the filename from which the block reads, execute:
set_param('myModel/myReader','Filename',myName)
where myName is a string/char vector containing the name of the file from which you want to read. In your APP code, insert that set_param code to react to a change in the filename.
Note that you cannot change the file name on the Simulink block while the model is running, so make sure the model is stopped before you execute this set_param.
To run the model programtically, use sim, e.g.
sim('myModel')
Roberto Lemaitre
Roberto Lemaitre 2021년 5월 24일
Thanks a lot!! it worked!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Block Libraries에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by