Calling videos from a folder in every iteration
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
NAVNEET NAYAN
el 19 de En. de 2020
Comentada: NAVNEET NAYAN
el 20 de En. de 2020
clc;
clear all;
close all;
number=45;
strng=num2str(number);
Folder = 'D:\project\Fingerspelling pics\';
for k=1:length(strng)
I(k)=str2num(strng(k));
aFile = fullfile(Folder, 'I(k).mp4');
videoFReader = vision.VideoFileReader(aFile);
videoPlayer = vision.VideoPlayer;
while ~isDone(videoFReader)
frame = step(videoFReader);
step(videoPlayer,frame);
end
end
My aim is to play the 4th and 5th video from the 'Folder' described in the code above. But when I am running the code it is producing error, since there is no any folder with the name I(k) in the 'Folder'. I want that as the value of I(k) changes in every iteration, correspondingly the video should be played from the folder. For example :- Here value of I(k) will be 4 and 5 of type 'double' in corresponding iterations and I have also my files 4.mp4 and 5.mp4 saved in 'Folder'. Please tell me how I can call and play the videos from 'Folder' using I(k) values.
0 comentarios
Respuesta aceptada
Sindar
el 20 de En. de 2020
Putting I(k) in quotes makes Matlab read it as a char instead of a variable. It is literally looking for I(k).mp4. To use the value of I(k), simply put (note the double quotes):
aFile = fullfile(Folder, I(k) + ".mp4");
Matlab automatically converts the number in I(k) into a string for addition. (But, doesn't do the same for adding to a char like '.mp4')
But, there's actually a way to simplify your code a bit, since you can directly index into the strng char:
clc;
clear all;
close all;
number=45;
strng=num2str(number);
Folder = 'D:\project\Fingerspelling pics\';
for k=1:length(strng)
aFile = fullfile(Folder, [strng(k) '.mp4']);
videoFReader = vision.VideoFileReader(aFile);
videoPlayer = vision.VideoPlayer;
while ~isDone(videoFReader)
frame = step(videoFReader);
step(videoPlayer,frame);
end
end
Here, the addition is done by concatenating chars..
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!