MATLAB: ‘uigetimagefile’ error in R2020a

MATLABr2020auigetimagefile

I have some old code files that used 'uigetimagefile' function. I knew they worked properly in R2018, R2019.
Today, when I tried to run those files on my new laptop with R2020a Update 4 installed. It complained about 'uigetimagefile' error immediately without poping up the file selection dialog:
>> uigetimagefile
Error using message/getString
Unable to load a message catalog 'mg:textedit'. Please check the file location and format.
Error in uigetimagefile (line 47)
dialogTitle = getString(message('mg:textedit:ImageInsertTtile'));
It wired as I didn't change any piece of the code and it stopped working.
So I tried to solve the problem by myself. It looks like the line 47 of uigetimagefile.m only sets the title of dialog. So I tried to modify that line using admin privilege to:
dialogTitle = 'Choose image file(s)';
Interestingly, the file selection window appeared and let me select an image file. However, as soon as I clicked the 'OK' button, another error appeared that prevented the function returning the selected file name to my code.
>> uigetimagefile
Unable to resolve the name GLUE2.Util.isValidImage.
Error in uigetimagefile (line 72)
elseif ~GLUE2.Util.isValidImage(filename)
I am stuck now. I cannot understand why the working code breaks in a newer release. Is the uigetimagefile function deprecated? Or is there anything missing in my new installation of Matlab?

Best Answer

Yes, evidently it's deprecated and has now been removed. I'd use uigetfile():
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = pwd; % or 'C:\wherever';
if ~isfolder(startingFolder)
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*'); % or *.png - whatever extension you want.
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
Or even better, make a GUI and have a listbox where they user can simply click on the image they want.