How can I write this animated figure as a movie?
2 views (last 30 days)
This is a scaled-down model of a larger bit of code I have been trying to write to generate an animated plot of audio measurements taken in a matrix of 10 x 10 microphone positions - 10 simulatneous channels per each of the 10 positions (well, 11 channels were recorded at each position, but I only need 10 of them, hence the indexing in the example datacall format from the real code). Was unable to get it to work properly at "full-scale" (no errors, but an almost "jammed" figure, so probably wildly inefficient processing), so made a small model of it to demostrate what I'm trying to achieve. Further to saving the animated plot as a movie, if anyone has any other suggestions on how to improve the code, I'd be very grateful to hear them.
I've tried the things suggested in the documentation for writeAnimation and fanimator, but I don't think I'm giving those functions the correct type of figure/data to write.
Many thanks in advance!
% "SCALE MODEL" of 10x10 PLOTTING CODE
% Build random matrices for example purposes - i.e., 5 "channels" of audio, each
% 20 "samples" long. Each five channel signal "played" from five
% positions, resulting in a 5 x 5 matrix of microphones/measurements/audio
fs = 5; % Otherwise 48000 for audio measurements.
a = -1; % Generate values between -1 and 1 to simulate audio signals.
b = 1;
Position1 = a + (b - a) .* rand(20,5); % Would call audio data here.
Position2 = a + (b - a) .* rand(20,5); % Format: Pos01audio = Pos01audiodata.audio(:,1:10);
Position3 = a + (b - a) .* rand(20,5); % Should audio vectors be tranposed into rows?
Position4 = a + (b - a) .* rand(20,5);
Position5 = a + (b - a) .* rand(20,5);
[NumSamples] = size(Position1(:,1)); % Get length of audio vectors from any; all measurements are the same length; 4secs or 4*fs.
NumSamples = NumSamples(1,1);
for i = 1 : NumSamples % Length of audio file in samples.
PlotMatrix = [Position1(i,:); Position2(i,:); Position3(i,:); Position4(i,:); Position5(i,:)]; % Concatenate arrays into matrix to be rewritten in 'for' loop.
OutputPlot = surf(PlotMatrix);
pause(1/fs) % Make pause equivalent to sample rate.