Video file of changing solid colors
Show older comments
Hello. I want to create a video file of a solid screen changing colors. I am trying to change the color of the figure systematically through hexcodes and record this as a single video. This will be used ultimately for spectral reflectance recordings of different hexcodes, so I want a single stimulus video displaying one color at a time and changing color after a few seconds. This is the code I have so far, when d is a column of hexcodes. So far, this seems to be changing the background color of an empty plot and only 'recording' the last image to the .mp4. Any help would be appreciated
HexCodes = VideoWriter('\Users\~\Documents\MATLAB\Hexcode_Colors.mp4','MPEG-4');
open(HexCodes);
fig = gcf;
set(gca,'visible','off', 'xtick',[])
H = [0 0 0];
fig = figure('Color', H);
hold;
for i = 1:length(d)
d(i,1)
set(gcf,'color',ans)
pause(.05);
f = getframe;
writeVideo(HexCodes,f);
clf
end
close(HexCodes);
Accepted Answer
More Answers (1)
darova
on 11 Sep 2019
TRY
HexCodes = VideoWriter('\Users\~\Documents\MATLAB\Hexcode_Colors.mp4','MPEG-4');
HexCodes.FrameRate = 30; % Frames per second (speed of video)
open(HexCodes);
H = [0 0 0];
fig = figure('Color', H);
set(gca,'visible','off', 'xtick',[])
d = jet(100); % create 100 colors of 'jet' colormap
for i = 1:size(d,1)
set(gcf,'color',d(i,:))
pause(.1);
f = getframe;
writeVideo(HexCodes,f);
clf
end
close(HexCodes);
1 Comment
Olivia Harris
on 11 Sep 2019
Categories
Find more on Video Formats and Interfaces 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!