In order to achieve the desired result of recording audio and video simultanteously, consider using 'videoinput' and 'audiorecorder' functions. The 'start', 'stop' functions for the 'videoinput' object and 'record', 'stop' functions for the 'audiorecorder' object can be used simultaneously.
If the video is to be recorded using webcam of a Windows device, the 'Image Acquisition Toolbox Support Package for OS Generic Video Interface' will need to be installed. Here is an example of how to set up the 'videoinput' and 'audiorecorder':
vid = videoinput('winvideo', 1);
vid.FramesPerTrigger = Inf;
vid.LoggingMode = 'memory'
Fs = 44100;
nBits = 16;
nChannels = 1;
% These values can be adjusted
recObj = audiorecorder(Fs, nBits, nChannels);
The 'getdata' and 'getaudiodata' functions can be used to obtain the data from the 'videoinput' and 'audiorecorder' functions respectively.
In order to play the audio and video, you can use the 'sound' and 'implay' functions respectively. Here is an example:
videoFrames = getdata(vid);
audioData = getaudiodata(recObj);
sound(audioData, Fs); % Play audio using 'sound' function
implay(videoFrames); % Play video using 'implay' function
Refer to the following MathWorks documentations to know more:
'Image Acquisition Toolbox Support Package for OS Generic Video Interface': https://www.mathworks.com/matlabcentral/fileexchange/45183-image-acquisition-toolbox-support-package-for-os-generic-video-interface
Thanks.