Errors with audiorecord function

1 回表示 (過去 30 日間)
Nikos Korobos
Nikos Korobos 2022 年 3 月 18 日
コメント済み: Nikos Korobos 2022 年 3 月 22 日
Hello everyone, I've written the below code so far.
Need Matlab to record(function to be running/active) for as long the button is pressed.
Then use the above running time as an input for the record function (screenshot).
Imagine it being like a play/pause button.
Gives me some errors
Can I use while (as long the state button value is True) instead of if(skips some code parts)?
Thanks in advance
  1 件のコメント
Nikos Korobos
Nikos Korobos 2022 年 3 月 18 日
Is it possible to replace the if with a while?

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2022 年 3 月 18 日
Yes, it is possible. However, you cannot achieve your goals by doing that.
You are in the middle of a callback that fires every time the state of the button changes -- which can mean that it was pressed to start or can mean that it was pressed to end.
You should have your app store the current status, currently recording or not. You should have your app store the recorder object (at the app level).
When the button is pushed, have the value changed function check to see if it is a request to start recording or to stop recording.
  • If it is a request to start recording and you are already recording, either discard the press or else stop the existing recording and continue on as if you were not already recording.
  • If it is a request to start recording and you are not already recording (or you "fell through" after stopping an existing recording), create the recorder object and store it at the app level, and set your state to "recording", activate the record() method of the recorder, and return from the callback.
  • If it is a request to stop recording and you are not already recording, discard the press
  • If it is a request to stop recording and you are currently recording, stop the recording, grab the data, remove the recorder object, set your state to not-recording, and enable any actions that should not be possible to perform until you have recorded data, and return
When you activate the record() method, I recommend that you put in a maximum length, to prevent it from overflowing the memory.
  13 件のコメント
Nikos Korobos
Nikos Korobos 2022 年 3 月 22 日
Hello again, so I've done some testing with your suggestions and my code is currently like this.
Although it does run and the Record button wont give me any errors, it doesn't seem to record anything.
Any ideas?
Thanks in advance
Nikos Korobos
Nikos Korobos 2022 年 3 月 22 日
I have also added a Properties section

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by