Error in function colorMatchingFunctions in "Digital Image Processing Using MATLAB(3rd)"

Hi, I'm very new to MATLAB and I am having some trouble. I have had a problem but nobody seems to be able to explain or solve it in plain English. Could somebody please explain what this error is and how to fix it?
the function provided in the book "Digital Image Processing Using MATLAB" as followed:
function out = colorMatchingFunctions
% colorMatchingFunctions Color-matching functions.
% colorMatchingFunctions returns a table containing the color matching
% functions for the CIE 1931 Standard Observer. The table contains the
% variables lambda, x, y, and z. The color matching functions are
% returned for wavelengths between 360nm and 830nm at intervals of lnm.
persistent t
if isempty(t)
% 现在版本可能不接受这种带空格为文件名?
t = readtable('CIE 1931 Standard Observer (1nm).xlsx','UseExcel',false);
end
out = t;
when the function is called in 2022a version, the error massage "Error in colorMatchingFunctions (line 18)
t = readtable("CIE 1931 Standard Observer (1nm).xlsx",'UseExcel',false);" displayed. Could someone please expalin why it is?

13 Comments

My first guess would be that likely there is no file named CIE 1931 Standard Observer (1nm).xlsx in the current directory or on the MATLAB path.
If I understand correctly there is (probably) a copy of the file in https://github.com/mathworks/matlab-color-tools/releases/tag/v2.1.2
the file 'CIE 1931 Standard Observer (1nm).xlsx' exist in the directory.
We would need to see the complete error message.
Also, please show us the output of
ls('CIE*.xlsx')
>> colorMatchingFunctions
Error using readtable
First argument must be a string array, character vector, or cell array of character vectors.
Error in colorMatchingFunctions (line 18)
t = readtable('CIE 1931 Standard Observer (1nm).xlsx',...
Please show the the output of
which -all readtable
I tested in the marked release, R2022b, and I cannot reproduce that indicated error message
>> readtable(struct())
Error using readtable
"filename" must be a string scalar or character vector.
>> readtable(3)
Error using readtable
"filename" must be a string scalar or character vector.
>> readtable(["",""])
Error using readtable
"filename" must be a string scalar or character vector.
>> readtable("")
Error using readtable
Unable to find or open ''. Check the path and filename or file permissions.
>> readtable({'helo'})
Error using readtable
"filename" must be a string scalar or character vector.
I was really confused by the error using readtable. Last week, I download the Color Tools for MATLAB v2.1.2 from the https://github.com/mathworks/matlab-color-tools/releases/tag/v2.1.2, and the function colorMatchingFunctions in the package of the Color Tools for MATLAB v2.1.2 excute successfuly in R2022b and R2023b. But, this week, the function failed to excute again with the same error message, I could not know what happened during the times.
Please, thank you for your time , the out of the commands you needed as followed,
>> which -all readtable
C:\Program Files\MATLAB\R2023b\toolbox\matlab\iofun\readtable.m
C:\Program Files\MATLAB\R2023b\toolbox\shared\io\general\+matlab\+io\@ImportOptions\ImportOptions.m % matlab.io.ImportOptions method
>> ls('CIE*.xlsx')
CIE 1931 Standard Observer (1nm).xlsx
If isempty(t)
Does that line of code really have a capital I in If rather than if ?
Please attach your colorMatchingFunctions.m file so I can examine it for odd characters.
the function included in the package v2.1.2 online excute once successfully last week, now it failed to excute with the same error message. Furthermore, there is not a capital I in if isempty(t) statement. thanks a lots.
function out = colorMatchingFunctions
%colorMatchingFunctions Color-matching functions.
% colorMatchingFunctions returns a table containing the color matching
% functions for the CIE 1931 Standard Observer. The table contains the
% variables lambda, x, y, and z. The color matching functions are
% returned for wavelengths between 360nm and 830nm at intervals of 1nm.
% Written by Steve Eddins to accompany Digital Image Processing Using
% MATLAB, 3rd edition, Gatesmark Press, 2020,
% http://imageprocessingplace.com.
%
% Copyright 2019 The MathWorks, Inc.
% License: https://github.com/mathworks/matlab-color-tools/blob/master/license.txt
persistent t
if isempty(t)
t = readtable('CIE 1931 Standard Observer (1nm).xlsx',...
'UseExcel',false);
end
out = t;
Please attach the file as well using the paperclip icon. When you post a copy of the file, then sometimes characters in the file get converted so we cannot see the exact content of the file.
Because the error message you are getting, "First argument must be a string array, character vector, or cell array of character vectors." is one that I have not been able to replicate in the release you are running, I need to investigate whether there are invisible characters that are somehow changing meaning of the text.
please find the attachments using paperclip icon as you indicated, thank you for your help.
I do not see how that error could possibly occur in that call -- not unless the error is occurring deep in some internal function and the true traceback is being surpressed.
One way an error like that could happen deep in the internals, is if somewhere on your MATLAB path you have a third-party function that is interfering with execution.
Experiment with giving the command
restoredefaultpath; rehash toolboxcache
and then running the code again. If the code succeeds, or if the code gives an error such as
Unable to find or open 'CIE 1931 Standard Observer (1nm).xlsx'. Check the path and filename or file permissions.
then you have something on your MATLAB path that is causing problems.
If the problem does not go away with that experiment, then there is still the possibility that you have an interferring function in your current directory.
It is right that what you understanded that there are interfering cumstom function(s) in my current dirction. When I deleted all my functions but colorMatchingFunctions in my current direction, the function execute successfully. But I am not sure what function(s) lead to the error. Thank you very much.

Sign in to comment.

Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Release

R2022b

Asked:

on 18 Oct 2023

Commented:

on 24 Oct 2023

Community Treasure Hunt

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

Start Hunting!