Errors related to macOS version
3 views (last 30 days)
Show older comments
Frank O'Donnell
on 28 Feb 2023
Commented: Frank O'Donnell
on 4 Mar 2023
A friend gave me some MATLAB code written in R2017B on Windows.
It executes normally in R2018A on macOS 10.15 Catalina. However, it produces errors in R2018B, R2019B, R2020B and R2022B on macOS 13.2 Ventura.
The specific errors are:
Error using textscan. Invalid file identifier. Use fopen to generate a valid file identifier.
Error while evaluating UIControl Callback.
I haven't previously run into MATLAB errors that are related to the computer OS version rather than the MATLAB version. Are these likely to be addressed in a pending MATLAB release? Or do I need to look at revising the code to get it to run on the Ventura Mac?
0 Comments
Accepted Answer
Walter Roberson
on 28 Feb 2023
It is difficult to be certain without seeing the code, but my first guess would be:
that the code has a call similar to
[filename, pathname] = uigetfile(some parameters);
fullname = [pathname filename];
That code would fail if the returned pathname from uigetfile is not empty and did not end in a directory separator.
Code similar to the above should always be rewritten more like
[filename, pathname] = uigetfile(some parameters);
fullname = fullfile(pathname, filename);
fullfile() automatically detects whether the given path already ends in a directory separator, and if not then automatically adds one.
(To be more correct, fullfile removes all trailing directory separators from the directory passed in, and then inserts a single copy of the directory separator appropriate to the operating system.)
It is common for people to assume that uigetfile() and uigetdir() return paths that end in a directory separator, but the function has never promised that -- and the function is not guaranteed to be consistent as to whether it provides the separator or not. The answer might be different, for example, for the current directory than for other directories.
3 Comments
Walter Roberson
on 3 Mar 2023
[FileName, PathName] = uigetfile;
if ~ischar(FileName)
return; %user asked to cancel
end
FileName = fullfile(PathName, FileName);
[fid1, msg] = fopen(FileName, 'r');
if fid1 < 0
error('Failed to open file "%s" because "%s"', FileName, msg);
end
...
fclose(fid1);
More Answers (0)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!