Borrar filtros
Borrar filtros

error in neural network for c#(.net Assemly)

4 visualizaciones (últimos 30 días)
Yang-Hung Hsiao
Yang-Hung Hsiao el 16 de Oct. de 2021
Respondida: Nihal el 26 de Jul. de 2024
Hello,
I always got same error all the time. I already no ideal what is the misdake i made.
C# error information:
... MWMCR::EvaluateFunction error ...
The 'STRING' input must be either a char row vector, a cell array of char row vectors, or a string array.
Error in => Mynntest.m at line 7.
Would anyone provide a direction for me ?
---------------------------------
My script :
I compile my script for C#(.net Assemly). (storage path:C:\\ANN )
My C#:
Error information in C#:

Respuestas (1)

Nihal
Nihal el 26 de Jul. de 2024
The error message you're encountering indicates that a function in your MATLAB code expects a string input in a specific format, but it is not receiving it in the correct format. This is a common issue when interfacing MATLAB code with C# via the MATLAB Compiler Runtime (MCR).Steps to Troubleshoot and Resolve the Issue
Check the Input Type:
  • Ensure that the input you are passing from C# to MATLAB is in the correct format. The error message specifies that the input must be a char row vector, a cell array of char row vectors, or a string array.
Review the MATLAB Function:
  • Open the MATLAB function Mynntest.m and look at line 7. Identify the variable that is causing the error and ensure it is being passed the correct type of string input.
Convert Input in C#:
  • Ensure that the string you are passing from C# is properly converted to a format that MATLAB can understand.
Example C# Code for Correct String Formatting
Here’s an example of how you can pass a string from C# to MATLAB using the MATLAB Compiler Runtime:
csharp
using MathWorks.MATLAB.NET.Arrays; // Ensure you have this namespace
public void CallMatlabFunction()
{
// Example string input
string inputString = "example input";
// Convert the C# string to a MATLAB string
MWCharArray matlabString = new MWCharArray(inputString);
try
{
// Assuming you have a compiled MATLAB function called 'Mynntest'
MynntestClass myMatlabFunction = new MynntestClass();
// Call the MATLAB function with the properly formatted string
myMatlabFunction.Mynntest(matlabString);
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
Example MATLAB Function
Here’s an example of what your MATLAB function might look like:
function output = Mynntest(inputString)
% Ensure the input is in the correct format
if ischar(inputString) || iscellstr(inputString) || isstring(inputString)
% Your function logic here
disp(inputString);
output = 'Success';
else
error('The ''STRING'' input must be either a char row vector, a cell array of char row vectors, or a string array.');
end
end
Summary
  • Ensure Input Type: Verify that the input being passed from C# to MATLAB is in the correct format.
  • Review MATLAB Code: Check the MATLAB function for the expected input format.
  • Convert Input in C#: Use MWCharArray to convert C# strings to MATLAB-compatible strings.
By ensuring that the input type matches the expected format in MATLAB, you should be able to resolve the error.

Categorías

Más información sobre MATLAB Compiler SDK 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!

Translated by