"Undefined function for input arguments of type 'char'" but the function is designed to take chars.

229 次查看(过去 30 天)
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?

采纳的回答

Rik
Rik 2020-1-24
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 个评论
Isaac Friedman
Isaac Friedman 2020-1-24
编辑:Isaac Friedman 2020-1-24
It is possible if you define those other functions outside of the classdef i.e.:
classdef BlockGenFunctions
methods(Static)
function CreateInputArrayFromFile ()
%stuff goes here
InputChunk () %function call
%some other stuff
end
end
end
function InputChunk ()
%different stuff goes here
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by