MATLAB: Not enough input arguments in a function script

inputargumentsMATLAB

I have a main script in which I am using diffrent functions that I made but it is giving an error in one of the function. And the error in one line of a particular function is 'Not enough input arguments'. Line 17 has an error Here is the function:
function [NodeMat]=Function_Sofistik_ReadNodes(FileName,NodeIDstr)
% clear all;close all;clc
% FileName=['MainModel' '_NODES_' '.lst']; % Sofistik .lst file name
% NodeIDstr='DATA EXTRACTION: NODE DATA'; % Header to search in Sofistik nodes output file
addpath Functions;
addpath SofistikFiles ;
% Read node coordinates output file and save data
fid_node=fopen(FileName,'r');
countRN=1;
while 1
line_node=fgetl(fid_node);
if ~ischar(line_node);
break;
end
NodeFileData{countRN,1}=line_node;
if (isempty(NodeFileData{countRN,1},NodeIDstr))~=1
break;
NodeLineNo=countRN;
end
countRN=countRN+1;
end
fclose(fid_node);
% Save Nodes
countSN=1;
while isnumeric(str2num(NodeFileData{NodeLineNo+countSN+1,1})) && isempty(str2num(NodeFileData{NodeLineNo+countSN+1,1}))==0
TempNode=str2num(NodeFileData{NodeLineNo+countSN+1,1});
if length(TempNode)==4 && TempNode(1)~=0
NodeMat(countSN,:)=str2num(NodeFileData{NodeLineNo+countSN+1,:});
end
countSN=countSN+1;
end

Best Answer

Line 17 is the first place that you refer to NodeIDstr inside the function.
You appear to be calling the function with only a single parameter (the file name) without passing in the second parameter (NodeIDStr)
if (isempty(NodeFileData{countRN,1},NodeIDstr))~=1
You are passing two parameters to isempty() but isempty() only accepts one parameter.
You are not seeing the error from isempty() because isempty() does not get control to check number of parameters until after NodeIDstr is evaluated to try to construct the second parameter.
I suspect you are thinking something like
if contains(NodeFileData{countRN,1}, NodeIDstr)
but if so then you need to be careful because contains() is happy to match substrings. contains('golum101','lum10') is true for example. You should probably break out the node name from the line and compare for equality. For example,
lineid = regexp(NodeFileData{countRN,1}, '(?<=^\s*Node\s+=\s+)\w+(?=\s*:)', 'match');
if strcmp(lineid, NodeIDstr)
This particular code would be for a case in which the node input lines were of the form
Node = NAME : something
where 'Node' =' and ':' are literal and NAME is the part you are looking to match and the something will be ignored
Related Question