Writing a frame to a video error
    6 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Yanjika O
 le 29 Juil 2020
  
    
    
    
    
    Commenté : Yanjika O
 le 29 Juil 2020
            Hi, 
I wrote the following code for repeatedly reading excel file and scatter plotting then writing a video from it.
clear all;clc;
filename1='x_recall_safeaudio_shockvideo.csv';
filename2='y_recall_safeaudio_shockvideo.csv';
col='B':'F';
repeats=5;
for i=1:repeats
    clear X; clear Y;
    X=xlsread(filename1,regexprep(filename1,'.csv',''),strcat(col(i),':',col(i)));
    Y=xlsread(filename2,regexprep(filename2,'.csv',''),strcat(col(i),':',col(i)));
    figure(i);
    plot1=scatter(X(1),Y(1),100,'b','filled');
    grid on
    xlim([-350 350]);
    ylim([-350 350]);
    xlabel('[px]')
    ylabel('[px]')
    title('Animal movement during conditioning');
    for j=2:length(X)
        plot1.XData=X(j);
        plot1.YData=Y(j);
        drawnow
        F(j)=getframe(gcf);
    end
    writerObj=VideoWriter(strcat('Conditioning',num2str(i),'.mp4'),'MPEG-4');
    writerObj.FrameRate=30;
    open(writerObj);
    writeVideo(writerObj,F(j));
    close(writerObj);
    close all
end
However the generated video doesn`t have any frame in it. 
Please give me your recommendations.
Thank you.
0 commentaires
Réponse acceptée
  JESUS DAVID ARIZA ROYETH
      
 le 29 Juil 2020
        you need to rearrange some things:
clear all;clc;
filename1='x_recall_safeaudio_shockvideo.csv';
filename2='y_recall_safeaudio_shockvideo.csv';
col='B':'F';
repeats=5;
for i=1:repeats
    clear X; clear Y;
    X=xlsread(filename1,regexprep(filename1,'.csv',''),strcat(col(i),':',col(i)));
    Y=xlsread(filename2,regexprep(filename2,'.csv',''),strcat(col(i),':',col(i)));
    figure(i);
    plot1=scatter(X(1),Y(1),100,'b','filled');
    grid on
    xlim([-350 350]);
    ylim([-350 350]);
    xlabel('[px]')
    ylabel('[px]')
    title('Animal movement during conditioning');
    writerObj=VideoWriter(strcat('Conditioning',num2str(i),'.mp4'),'MPEG-4');
    writerObj.FrameRate=30;
    open(writerObj);
    for j=2:length(X)
        plot1.XData=X(j);
        plot1.YData=Y(j);
        drawnow
        F(j)=getframe(gcf);
        writeVideo(writerObj,F(j));
    end  
    close(writerObj);
    close all
end
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

