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

1 Ansicht (letzte 30 Tage)
Solmon Raju
Solmon Raju am 14 Feb. 2020
Kommentiert: Walter Roberson am 14 Feb. 2020
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

Antworten (1)

Bhaskar R
Bhaskar R am 14 Feb. 2020
Bearbeitet: Bhaskar R am 14 Feb. 2020
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
  2 Kommentare
Walter Roberson
Walter Roberson am 14 Feb. 2020
uigetfile returns the name of a file, not the contents of the file. But imageArray is the contents of one of the files, not the name of a file.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by