function in app give "undefined function for input arguments"

조회 수: 2 (최근 30일)
Tyler
Tyler 2023년 1월 31일
댓글: Walter Roberson 2023년 2월 8일
Sample of one of the functions in my code. I made functions for my 2 other apps and they worked fine once I included the correct inputs but I cannot get the correct inputs other than "app" for this code and it gives me a different error than I have seen. Code below:
function PostTestAONButton(app)
if app.MeasurementRangeAONButton.Value == 1
file = dir(fullfile(directory,'*POST-TEST*AON_.txt'));
for i = 1:numel(file)
filepath = fullfile(file(i).folder, file(i).name);
data_in = readmatrix(filepath);
% Grabbing only the frequency and SE values
x = data_in(:,1);
y = data_in(:,3);
% Plotting data based on various options selected
if app.IncludeonLegendCheckBoxAON.Value == 1
if app.MRMarkersButton.Value == 1
plot(x,y,"Color",app.MRColorDropDown.Value,'LineWidth',str2double(app.LineWidthDropDown.Value), ...
Marker=app.MRMarkerDropDown.Value,DisplayName='MR');
else
plot(x,y,"Color",app.MRColorDropDown.Value,'LineWidth',str2double(app.LineWidthDropDown.Value), ...
DisplayName='MR');
end
else
if app.MRMarkersButton.Value == 1
plot(x,y,'HandleVisibility','off',"Color",app.MRColorDropDown.Value,'LineWidth',str2double(app.LineWidthDropDown.Value), ...
Marker=app.MRMarkerDropDown.Value);
else
plot(x,y,'HandleVisibility','off',"Color",app.MRColorDropDown.Value,'LineWidth',str2double(app.LineWidthDropDown.Value));
end
end
end
else
end
end
  댓글 수: 7
Voss
Voss 2023년 2월 7일
@Walter Roberson: "before the definition of the nested function" I believe should be, "before the execution of the nested function"
outer % works
ans = 16
outer2 % fails
Unrecognized function or variable 'B'.

Error in solution>outer2/inner (line 16)
C = A + B;

Error in solution>outer2 (line 14)
inner() % fails because B is not defined yet
function outer
A = 5;
function C = inner % defining inner() here is ok, as long as B is defined before inner() is called
C = A + B;
end
B = 11; % B defined after the definition of inner() but before the execution of inner() works
inner()
end
function outer2
A = 5;
inner() % fails because B is not defined yet
function C = inner
C = A + B;
end
B = 11;
end
Walter Roberson
Walter Roberson 2023년 2월 8일
Interesting, my memory had always been that the variable had to be defined before the nested function definition. Either that changed or my memory blipped again. Either of those are real possibilities ;-)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by