hi everyone.,how to solve Index exceeds matrix dimensions in this particular code ?

error:
Index exceeds matrix dimensions.
Error in download (line 19)
if ~exist(fullfile(output_directory, [regexprep(urls{i}(24, end), '/', '_')]))
code:
output_directory = 'sbu_images';
urls = textread('SBU_captioned_photo_dataset_urls.txt', '%s', -1);
if ~exist(output_directory, 'dir')
mkdir(output_directory);
end
rand('twister', 123);
urls = urls(randperm(length(urls)));
for i = 1 : length(urls)
if ~exist(fullfile(output_directory, [regexprep(urls{i}(24, end), '/', '_')]))
cmd = ['wget -t 3 -T 5 --quiet ' urls{i} ...
' -O ' output_directory '/' regexprep(urls{i}(24, end), '/', '_')];
unix(cmd);
fprintf('%d. %s\n', i, urls{i});
end
end

 Accepted Answer

If I recall correctly, the obsolete routine textread() will return a cell array of character vectors when you use the %s format that you used. Then your code loops through each entry in that cell array, extracting it with urls{i} to get a character vector. But then you try to take the last character of row 24 of that character vector with your (24, end) and that character vector does not have 24 rows.
If you want to extract from position 24 to the end you would use (24:end) not (24,end)

6 Comments

hi sir. after changing the (24:end) instead of (24,end).the program is run but after the END its getting error.
like: 'wget' is not recognized as an internal or external command, operable program or batch file.
please help me to solving this problem.
sir,i download the wget for window and store in c drive. i have also set a path in environment variable. but still its showing error.
Build the path in as part of cmd
cmd = ['"C:\Users\suramya\Documents\gnu_wget\wget.exe" -t 3 -T 5 --quiet ' urls{i} ...
' -O ' output_directory '/' regexprep(urls{i}(24, end), '/', '_')];
... using the appropriate path for your situation.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!