Error Using video Writer Frame Must be 560 by 420
38 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I make simple animate moving vehicle. This is my code
clear all; close all; clc;
%Untuk bikin video percobaan lurus dituker aja yg komen ama bukan komen
%Read .xls = kiri nama file, kanan blok kolom-baris
%% Leader
dataxleader = xlsread('DMPC_Train_PF.xlsx','A3:A102');
datayleader = xlsread('DMPC_Train_PF.xlsx','B3:B102');
%% Follower
% Follower 1
dataxfollower1 = xlsread('DMPC_Train_PF.xlsx','C3:C102');
datayfollower1 = xlsread('DMPC_Train_PF.xlsx','D3:D102');
% Follower 2
dataxfollower2 = xlsread('DMPC_Train_PF.xlsx','E3:E102');
datayfollower2 = xlsread('DMPC_Train_PF.xlsx','F3:F102');
% Follower 3
dataxfollower3 = xlsread('DMPC_Train_PF.xlsx','G3:G102');
datayfollower3 = xlsread('DMPC_Train_PF.xlsx','H3:H102');
% Follower 4
dataxfollower4 = xlsread('DMPC_Train_PF.xlsx','I3:I102');
datayfollower4 = xlsread('DMPC_Train_PF.xlsx','J3:J102');
% Follower 5
dataxfollower5 = xlsread('DMPC_Train_PF.xlsx','K3:K102');
datayfollower5 = xlsread('DMPC_Train_PF.xlsx','L3:L102');
% Follower 6
dataxfollower6 = xlsread('DMPC_Train_PF.xlsx','M3:M102');
datayfollower6 = xlsread('DMPC_Train_PF.xlsx','N3:N102');
%% Delta Jarak
% Delta Jarak 1
deltajarak1 = xlsread('DMPC_Train_PF.xlsx','AG3:AG102');
posisideltax1 = [dataxfollower1(1:100) + dataxleader(1:100)] / 2 ;
posisideltay1 = [datayfollower1(1:100) + datayleader(1:100)] / 2 ;
% Delta Jarak 2
deltajarak2 = xlsread('DMPC_Train_PF.xlsx','AH3:AH102');
posisideltax2 = [dataxfollower2(1:100) + dataxfollower1(1:100)] / 2 ;
posisideltay2 = [datayfollower2(1:100) + datayfollower1(1:100)] / 2 ;
% Delta Jarak 3
deltajarak3 = xlsread('DMPC_Train_PF.xlsx','AI3:AI102');
posisideltax3 = [dataxfollower3(1:100) + dataxfollower2(1:100)] / 2 ;
posisideltay3 = [datayfollower3(1:100) + datayfollower2(1:100)] / 2 ;
% Delta Jarak 4
deltajarak4 = xlsread('DMPC_Train_PF.xlsx','AJ3:AJ102');
posisideltax4 = [dataxfollower4(1:100) + dataxfollower3(1:100)] / 2 ;
posisideltay4 = [datayfollower4(1:100) + datayfollower3(1:100)] / 2 ;
% Delta Jarak 5
deltajarak5 = xlsread('DMPC_Train_PF.xlsx','AK3:AK102');
posisideltax5 = [dataxfollower5(1:100) + dataxfollower4(1:100)] / 2 ;
posisideltay5 = [datayfollower5(1:100) + datayfollower4(1:100)] / 2 ;
% Delta Jarak 6
deltajarak6 = xlsread('DMPC_Train_PF.xlsx','AL3:AL102');
posisideltax6 = [dataxfollower6(1:100) + dataxfollower5(1:100)] / 2 ;
posisideltay6 = [datayfollower6(1:100) + datayfollower5(1:100)] / 2 ;
% word '' tuh biar deklarasi awal string aja, karena matlabnya butuh ga
% kaya python.
word1 = '';
word2 = '';
word3 = '';
word4 = '';
word5 = '';
word6 = '';
waktu = '';
%t dapet dari total waktu percobaan dibagi jumlah data(dengan asumsi prosesnya pake waktu yg relatif sama 38ms)
t = 15000.2336/100; %waktu bisa aja pake dari data tinggal ditambah
%ada geser dari waktu asli ke waktu plot beda 0.2s
%walaupun data asli juga waktunya kepengaruh ama processing speed pas video
%ke data excel
time = 0;
% repeat bisi diilangin soalnya cuma buat ngecek berulang ada salah ato ga
for repeat = 1:1
figure;
for i = 1:100 %1:jumlah data
time = time + t;
% Leader
plot(dataxleader(1:i),datayleader(1:i),'--m');
% text(dataxleader+1, datayleader+1, 'deltajarakl ')
circle (dataxleader(i),datayleader(i),5);
grid on;
hold on;
% Follower 1
plot(dataxfollower1(1:i),datayfollower1(1:i),'-.b');
% text(dataxfollower1+1, datayfollower1+1, 'deltajarak2 ')
circle (dataxfollower1(i),datayfollower1(i),5);
grid on;
hold on;
% Follower 2
plot(dataxfollower2(1:i),datayfollower2(1:i),'-.r');
% text(dataxfollower2+1, datayfollower2+1, 'deltajarak3 ')
circle (dataxfollower2(i),datayfollower2(i),5);
grid on;
hold on;
% Follower 3
plot(dataxfollower3(1:i),datayfollower3(1:i),'-.g');
% text(dataxfollower3+1, datayfollower3+1, 'deltajarak4 ')
circle (dataxfollower3(i),datayfollower3(i),5);
grid on;
hold on;
% Follower 4
plot(dataxfollower4(1:i),datayfollower4(1:i),'-.c');
% text(dataxfollower4+1, datayfollower4+1, 'deltajarak5 ')
circle (dataxfollower4(i),datayfollower4(i),5);
grid on;
hold on;
% Follower 5
plot(dataxfollower5(1:i),datayfollower5(1:i),'-.y');
% text(dataxfollower5+1, datayfollower5+1, 'deltajarak6 ')
circle (dataxfollower5(i),datayfollower5(i),5);
grid on;
hold on;
% Follower 6
plot(dataxfollower6(1:i),datayfollower6(1:i),'-.k');
circle (dataxfollower6(i),datayfollower6(i),5);
line([dataxleader(i),dataxfollower1(i)],[datayleader(i),datayfollower1(i)]);
line([dataxfollower1(i),dataxfollower2(i)], [datayfollower1(i),datayfollower2(i)]);
line([dataxfollower2(i),dataxfollower3(i)], [datayfollower2(i),datayfollower3(i)]);
line([dataxfollower3(i),dataxfollower4(i)], [datayfollower3(i),datayfollower4(i)]);
line([dataxfollower4(i),dataxfollower5(i)], [datayfollower4(i),datayfollower5(i)]);
line([dataxfollower5(i),dataxfollower6(i)], [datayfollower5(i),datayfollower6(i)]);
%title ama legend aku masih belum tau gimana dikeluarin dari
%loopnya biar prosesnya ga lemot tapi pas ke video tetep bisa
%soalnya ngatur fps diatur di akhir
title('Perubahan Posisi Mobile Robot Pada Percobaan Belok')
legend('Leader','Follower1','Follower2','Follower3','Follower4','Follower5','Follower6');
% writerObj.FrameRate = 26.1882 ;
xlim([-700 200]);
ylim([0 150]);
deltajarakcm1 = deltajarak1/1.5;
deltajarakcm2 = deltajarak2/1.5;
deltajarakcm3 = deltajarak3/1.5;
deltajarakcm4 = deltajarak4/1.5;
deltajarakcm5 = deltajarak5/1.5;
deltajarakcm6 = deltajarak6/1.5;
%delete biar tulisan word ama waktu ga tetep ada di plotnya
% delete(word1);
delete(waktu);
word1 = text(posisideltax1(i),posisideltay1(i),sprintf('delta Jarak1 = %.2f Pixel, (%.2f cm)',deltajarak1(i),deltajarakcm1(i)'));
waktu = text(10,10,sprintf('waktu1 = %.2f s',time))
delete(word2);
word2 = text(posisideltax2(i) + 10,posisideltay2(i)+10,sprintf('delta Jarak2 = %.2f Pixel, (%.2f cm)',deltajarak2(i),deltajarakcm2(i)'));
delete(word3);
word3 = text(posisideltax3(i) + 50,posisideltay3(i)+20,sprintf('delta Jarak3 = %.2f Pixel, (%.2f cm)',deltajarak3(i),deltajarakcm3(i)'));
delete(word4);
word4 = text(posisideltax4(i) - 10,posisideltay4(i)+30,sprintf('delta Jarak4 = %.2f Pixel, (%.2f cm)',deltajarak4(i),deltajarakcm4(i)'));
delete(word5);
word5 = text(posisideltax5(i) - 50,posisideltay5(i) + 40,sprintf('delta Jarak5 = %.2f Pixel, (%.2f cm)',deltajarak5(i),deltajarakcm5(i)'));
delete(word6);
word6 = text(posisideltax6(i) - 100,posisideltay6(i) + 50,sprintf('delta Jarak6 = %.2f Pixel, (%.2f cm)',deltajarak6(i),deltajarakcm6(i)'));
drawnow;
%getframe buat ambil frame
F(i) = getframe(gcf);
end
%video writer ya nama file
writerObj = VideoWriter('MPC Train.avi');
writerObj.FrameRate = 26.1882 ;
%frame rate aku dapet dari data/waktu
open(writerObj);
%bawah yang proses bikin videonya
for i = 1:length(F)
frame = F(i);
writeVideo(writerObj, frame);
end
close(writerObj);
end
close all;
But I have problem with the frame rate. How i fix this?
Error using VideoWriter/writeVideo (line 368)
Frame must be 560 by 420
Error in MPCTrainPFAnimation1 (line 218)
writeVideo(writerObj, frame);
0 commentaires
Réponses (1)
Walter Roberson
le 5 Jan 2021
Modifié(e) : Walter Roberson
le 5 Jan 2021
3 commentaires
Walter Roberson
le 5 Jan 2021
You are using getframe(), just the same as I discussed at https://www.mathworks.com/matlabcentral/answers/329710-how-to-save-a-figure-s-content-as-image#comment_1241428
Voir également
Catégories
En savoir plus sur Animation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!