I am getting the error invalid use of operator
309 次查看(过去 30 天)
显示 更早的评论
I am getting the error invalid use of operator when excuting this below.
data = AX3_readFile('accsamp.cwa','info',1);
4 个评论
DGM
2022-4-12
Line 7 of AX3_readFile.m is part of the function synopsis. If it's throwing an error on that line, then something is messed up with that file. Either it's been edited or replaced or something.
function data = AX3_readFile(filename, varargin)
%
% DATA = AX3_readFile(FILENAME, [OPTIONS])
%
% Reads in binary file as produced by AX3 accelerometer. Returns a
% struct filled with data from different modalities (ACC, LIGHT,
% TEMP). Relies on two external mex-functions (parseValueBlock.c,
% parseDate.c) that have to be compiled using the mex interface.
%
回答(1 个)
Riya
2023-11-19
Hello Nawfal Zakar,
As per my understanding, you are getting error that there is invalid use of operator.
Please note that the error "invalid use of operator" typically occurs when you use an operator incorrectly in your code. In the code you provided, the error is likely not related to the line you mentioned, as it appears to be a function call.
To troubleshoot the issue further, you should check the code surrounding the line that is causing the error. Here are some steps you can follow:
1. Check if the function `AX3_readFile` is defined correctly and accessible in your code. Make sure the function name is spelled correctly and that it is defined before you call it.
2. Verify that you have included any necessary libraries or modules that contain the definition of the `AX3_readFile` function. If the function is defined in a separate file or module, make sure you have imported it correctly.
3. Ensure that you are passing the correct arguments to the `AX3_readFile` function. Check the function's documentation or definition to see what arguments it expects and make sure you are providing them in the correct order and format.
4. Double-check the file name to ensure that it exists in the correct location and that you have read access to it. If the file is not in the same directory as your code, provide the full path to the file.
By carefully reviewing these aspects, you should be able to identify and resolve the "invalid use of operator" error in your code.
I hope it helps.
Regards
Riya
1 个评论
Walter Roberson
2023-11-19
- Whether a function is defined before you attempt to call it makes no difference to invalid use of operator. However, it is true that if you accidentally included an operator in a function name definition that you could get this error message
- If the libraries or modules defining a function are not accessible or not imported, then invalid use of operator in the file cannot be triggered. The error can only be triggered when a source code file is located and is parsed and has syntax problems
- If you make a mistake in passing arguments to a function, then you might get invalid use of operator in the call but it will not create any invalid use of operator inside the function -- not unless the function does something stupid like eval() character strings passed in by the user
- If the file name was not in the correct location or did not have read access, then you cannot get invalid use of operator inside the file. Invalid use of operator can only occur when a file has been successfully located and is parsed but turns out to have a syntax error (well, unless the code uses eval() or equivalent)
The correct solution was identified last year by @DGM in https://www.mathworks.com/matlabcentral/answers/1694835-i-am-getting-the-error-invalid-use-of-operator#comment_2100100 -- that the user's AX3_readFile source code is corrupted. (Or, possibly the user had a second AX3_readFile in their path that was corrupted.)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!