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

조회 수: 242 (최근 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