got an error "index exceed matrix dimension"

1 次查看(过去 30 天)
here sir iwant to read all my file 1224 numbers. But it just read & process only 13 number file then it said " index exceed matrix dimension".... plz help.here i used this following code
workingDir='E:\ flame 1 (500 fps)\';
imageNames = dir(fullfile(workingDir,'*.jpg'));
imageNames = {imageNames.name}';
imageStrings = regexp([imageNames{:}],'(\d*)','match');
imageNumbers = str2double(imageStrings);
[~,sortedIndices] = sort(imageNumbers);
sortedImageNames = imageNames('sortedIndices');
fileID = fopen('img_fstd2.dat','w');
for ii = 1:13%length(sortedImageNames)
I1 = imread(fullfile(workingDir,sortedImageNames{ii}));
for i=1:530
for j=1:380
if I1(i,j)<60
I1(i,j)=0;
elseif I1(i,j)>90
I1(i,j)=1;
end
end
end

回答(1 个)

Wayne King
Wayne King 2012-7-26
编辑:Wayne King 2012-7-26
I think you should determine where the error is occurring. In other words, if you remove this for loop:
for i=1:530
for j=1:380
if I1(i,j)<60
I1(i,j)=0;
elseif I1(i,j)>90
I1(i,j)=1;
end
end
Do you still get the error only running:
workingDir='E:\ flame 1 (500 fps)\';
imageNames = dir(fullfile(workingDir,'*.jpg'));
imageNames = {imageNames.name}';
imageStrings = regexp([imageNames{:}],'(\d*)','match');
imageNumbers = str2double(imageStrings);
[~,sortedIndices] = sort(imageNumbers);
sortedImageNames = imageNames('sortedIndices');
fileID = fopen('img_fstd2.dat','w');
for ii = 1:13%length(sortedImageNames)
I1 = imread(fullfile(workingDir,sortedImageNames{ii}));
end
Also, I don't think you need that complicated for loop:
for i=1:530
for j=1:380
if I1(i,j)<60
I1(i,j)=0;
elseif I1(i,j)>90
I1(i,j)=1;
end
end
How about just:
Il(Il<60) = 0;
Il(Il>90) = 1;

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by