"Undefined function for input arguments of type 'char'" but the function is designed to take chars.
264 views (last 30 days)
Show older comments
I'm trying to call a function when a button is pressed in an app. I've created a class containing all the relevant functions in a static method (many of the functions reference one another, which is where these issues start to arrise). The App takes 2 files, chosen by the user, and feeds them to the function called by the button press. Here's the function call:
function SelectButtonPushed(app, event)
disp(app.SettingsFileEditField.Value)
disp(app.AssemblyEditField.Value)
BlockGenFunctions.CreateInputArrayFromFile(convertCharsToStrings(app.SettingsFileEditField.Value), convertCharsToStrings(app.AssemblyEditField.Value), [-500, 0]);
end
The error comes when that function calls another function. Here's the complete error message:
Undefined function 'InputChunk' for input arguments of type 'char'.
Error in BlockGenFunctions.CreateInputArrayFromFile (line 115)
InputChunk(cn, simFileName, 0 + coord(1),240*(i-1) + coord(2), i);
The issue with that is, the function is specifically designed to tach character vectors and/or strings. Here's the important parts of the function in question:
function InputChunk(chunkName, docname, modX, modY, index)
%create a subsystem to keep things organized
locName = strcat(docname, '/', chunkName); %the name of the document and subsystem where the chunk is being built
add_block('simulink/Ports & Subsystems/Subsystem',locName);
set_param(locName,'position',[-200+modX,0+modY,200+modX,200+modY]);
%...
%create annotation at the top of the input chunk
note = Simulink.Annotation(strcat(locName,'/', chunkName),'HorizontalAlignment', 'center');
%etc
end
So if the function specifically calls for char vectors, why is this error thrown?
0 Comments
Accepted Answer
Rik
on 24 Jan 2020
Generally the errors for functions that you have written yourself will not be this descriptive, unless you make them this descpritive yourself. The cause of this error tends to be that Matlab is unable to locate the function you are trying to call.
Set a breakpoint at the line of code that is calling the InputChunk function and execute
which InputChunk -all
That should give you the answer whether or not Matlab is able to find your function. If it doesn't show up, you need to make sure this function is either in the m file of the calling function, or is in an individual file on your path (and/or current directory).
3 Comments
More Answers (0)
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!