How can I write this animated figure as a movie?
Show older comments
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
% vectors.
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);
grid on
pause(1/fs) % Make pause equivalent to sample rate.
drawnow
end
Answers (1)
KSSV
on 12 Oct 2020
0 votes
10 Comments
Peter Beringer
on 12 Oct 2020
Edited: Peter Beringer
on 12 Oct 2020
Peter Beringer
on 12 Oct 2020
Rik
on 12 Oct 2020
Yes, there is a difference, and you can use functions like getframe to convert one to the other.
Peter Beringer
on 13 Oct 2020
forum full of so many [] condescending people refusing to accpet that not everyone was born knowing everything
You got a very good opinion.....
When you ask a question, if the question is already answered, why to explain the same? What's wrong in showing the link? It is the user who has to try, not like people here write and give you entire code.
If you have tried what sowin in the link....tell us what error you have? So that we can futher help you. You have to show the error not pointing the users here who are helping you.
Sorry, I meant to say surface plots, not figures (it's been a rotten day). So, I mean can a surface plot be captured as an image in the same way as a 2d plot,
Yes...you can ..see this link:
I hope you will not point out that people here are [] CONDESCENDING ..as a link is given.
Steven Lord
on 13 Oct 2020
It is possible to capture a surface plot as an image in the same way as a 2-d plot. See as an example:
% Sample data
[x, y, z] = peaks;
h = surf(x, y, z);
% Capture the first frame
M = getframe(gca);
[~, EL] = view;
for k = 0:180
% Rotate the axes
view(k, EL);
% Capture the next frame
M(end+1) = getframe(gca);
end
% Show the movie
movie(M)
But nothing in the code you've posted does any capturing of image data. Can you show us that section of your code and explain what happens when you run it that you want to fix and/or change (error messages, part of the image cut off, excessive whitespace, etc.)?
Peter Beringer
on 13 Oct 2020
Peter Beringer
on 13 Oct 2020
Peter Beringer
on 14 Oct 2020
Peter Beringer
on 14 Oct 2020
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!