Errors related to macOS version
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Frank O'Donnell
el 28 de Feb. de 2023
Comentada: Frank O'Donnell
el 4 de Mzo. de 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 comentarios
Respuesta aceptada
Walter Roberson
el 28 de Feb. de 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 comentarios
Walter Roberson
el 3 de Mzo. de 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);
Más respuestas (0)
Ver también
Categorías
Más información sobre File Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!