Array indices must be positive integers or logical values

조회 수: 3 (최근 30일)
Chang
Chang 2024년 10월 22일
댓글: Chang 2024년 10월 25일
I am training a neural network. When I execute this code in MATLAB software, it goes very smoothly. However, when I convert it to an exe for execution, I encounter this error when outputting "Array indices must be positive integers or logical values", but my output value must have negative numbers and floating point numbers, such as [0.06235, 0.3999,-0.0493]. How can I change the type so that I can continue the operation?
*This AI model does not apply to the round function. If the output value is changed to an integer, there will be problems with the operation below.
output = net(normalizedFeatures'); %<------- There's something wrong with this line
diff_0 = abs(output - 0);
diff_1 = abs(output - 1);
output_final = min(diff_0, diff_1);
output_final(diff_1 < diff_0) = 1;
output_final(diff_0 <= diff_1) = 0;
  댓글 수: 11
Cris LaPierre
Cris LaPierre 2024년 10월 24일
Can you please share NN_97.22.mat and one of your text files (the same ones that your executable is using)? You can attach them using the paperclip icon.

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Lord
Steven Lord 2024년 10월 24일
If you are attempting to compile code using MATLAB Compiler that calls load to load an object from a MAT-file and there is no indication in the code itself that MATLAB Compiler needs to package the code, the dependency analyzer may not be able to detect that it needs to include the definition of the class. This could cause it to be loaded not as an object but as a number or a struct (I'm not 100% certain which.) In this case use one of the workarounds in the "Callback Problems Due to Missing Functions" section of this documentation page, as this workflow is described by the Tip in that section of that documentation page.
I believe in the case you describe there's no indication that MATLAB Compiler needs to include the definition for the network object in the application, so your attempt to pass data into it for simulation into it doesn't call the network's overload of indexing but attempts to index into a "regular variable". You can't ask for element 0.06235 of a numeric array and that's the cause of the error.
  댓글 수: 2
Walter Roberson
Walter Roberson 2024년 10월 24일
If I recall correctly, if a class definition is not present at the time of a load(), then the data is loaded as a vector of uint8
Steven Lord
Steven Lord 2024년 10월 24일
I believe that's the case for a class defined in a classdef file. Classes defined using the older syntax are loaded in as a struct if the class definition isn't available IIRC.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by