clc
clear all
close all

% a ='C:\Users\Peixoto\Dropbox\blog\24 - Final Article\rosbag_Article2\frame\';
% A =dir( fullfile(a, '*.jpg') );
% fileNames = { A.name };
% for iFile = 1 : numel( A )
%   newName = fullfile(a, sprintf( 'frame%04d.jpg', iFile ) );
%   movefile( fullfile(a, fileNames{ iFile }), newName );    
% end 
dirData = dir('*.jpg');         %# Get the selected file data
fileNames = {dirData.name};     %# Create a cell array of file names
for iFile = 1:numel(fileNames)  %# Loop over the file names
  newName = sprintf('frame%04d.jpg',iFile-1);  %# Make the new name
  movefile(fileNames{iFile},newName);        %# Rename the file
end