Error in MATLAB executing max () function: Subscript index must be a positive integer type or logical type
An error occurred when using the Max () function of Matlab to find the maximum value for a column of double type data: The subscript index must be a positive integer type or a logical type. Here is a partial matlab code :
Frid = fopen (infile (i). Name, ' RT ');
Fwid = fopen (outfile, ' A + ');
A = Textscan (Frid, '%d%d%d%f ');
B = a{4};
Maxval = max (B);
I couldn't understand the reason for the mistake. At first I thought B was a problem, but when I looked at the MATLAB reference manual, I found it could be used. The subsequent use of clear clears the variable when the execution of similar code is successful, so I think it should be a variable problem.
The careful classmate may notice that the last line left the variable max and the right function Max have the same name. Yes, that's why the mistake happened. There is no Max variable for the first execution, so the max () function can execute correctly. With the first execution of the max variable generation, when the max () function is executed again, instead of the max () function that comes with MATLAB, the first generation of the variable max is used instead. And the variable max is not on this side as a function, but as an array, so the right side should be the subscript index (positive integer type or logical type), but B is not such a type. Error: The subscript index must be a positive integer type or a logical type.
The workaround is simple, as long as the variable max before the error line equals sign is changed to a variable name that is not the same as the function Max (), such as Maxval.
I first contact with Matlab, so will make some relatively low-level errors. Record it down to remind myself.