Error using == Number of array dimensions must match for binary array op.

2 次查看(过去 30 天)
myFolder = 'C:\Users\cse\Desktop\images';
% if ~isdir(myFolder)
% errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
% uiwait(warndlg(errorMessage));
% return;
% end
a=uigetfile('C:\Users\cse\Desktop\1.jpg');
filePattern = fullfile(myFolder, '*.jpg');
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
figure(k),imshow(imageArray);
if(a==imageArray)
disp('yes');
end
end

回答(1 个)

Bhaskar R
Bhaskar R 2020-2-14
编辑:Bhaskar R 2020-2-14
You are comparing character array with image matrix that is why you got error
if(a==imageArray)
disp('yes');
end
% a - Char array
% imageArray - Image numeric matrix
I think you are trying to compare filenames so replace if condition as
if(strcmp(a,baseFileName)
disp('yes');
end

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by