App Designer add function confused by variable names

조회 수: 6 (최근 30일)
Michael Van de Graaff
Michael Van de Graaff 2021년 3월 7일
댓글: Michael Van de Graaff 2021년 12월 3일
I've determined the problem and work around for my particular case, and wish to post it here for posterity.
The problem i encountered is this: when adding a new helper fuction in App Designer, the automatic code generation would occasionally place the new function inside of a previous function. This is visually and syntacally terrible, and i'm pretty sure it bricks most code too.
The source of the buggy behavior seems to be with variables whose names end with the word 'end' . I did NOT name any variable 'end', but 'variable_end' is sufficient to cause the problem.
I was able to create a minimal example.
methods (Access = private)
function results = not_buggy_names(app)
variable_named_with_endd = 1;
results = variable_named_with_endd;
end
end
If we have the already existing function not_buggy_names and now press the add function button we correctly get the following behavior
methods (Access = private)
function results = not_buggy_names(app)
variable_named_with_endd = 1;
results = variable_named_with_endd;
end
function results = func2(app)
% this is correctly placed
end
end
However, if instead we have the folowing initial function buggy_names, which contains the string 'end'
methods (Access = private)
function results = buggy_names(app)
variable_named_with_end = 1;
results = variable_named_with_end; % this line is the problem, putting comment here doesn't help
additional_code_doesnt_help = 1;
end
end
and now add a new function yields
methods (Access = private)
function results = buggy_names(app)
variable_named_with_end = 1;
results = variable_named_with_end;% this line is the problem, putting comment here doesn't help
additional_code_doesnt_help = 1;
function results = func2(app)
% The new function got placed within the previous function, but at the end
end
end
end
The variable with 'end' in the name does seem to need to be at the very end of the line.
For example, this code works fine:
methods (Access = private)
function results = fix_buggy_names(app)
variable_named_with_end = 1;
results = variable_named_with_end + 0; % now the line doesn't end with the sting 'end'
end
end
which produces
methods (Access = private)
function results = fix_buggy_names(app)
variable_named_with_end = 1;
results = variable_named_with_end + 0; % now the line doesn't end with the sting 'end'
end
function results = func2(app)
end
end

채택된 답변

Chidvi Modala
Chidvi Modala 2021년 3월 10일
I have brought this issue to the concerned people and it might be fixed in any future release.
  댓글 수: 2
Michael Van de Graaff
Michael Van de Graaff 2021년 3월 10일
Thank you very much.
Hopefully my post here provided sufficient information for others experiencing this problem to find my conclusion and work around.
Michael Van de Graaff
Michael Van de Graaff 2021년 12월 3일
I'd like to furthur note that the same/similar error occurs when I call legend on it's own.
So this breaks:
methods (Access = private)
function results = buggy_ftn(app)
f = figure;
ax = axes(f);
plot(ax,1:15);
legend % if this is commented, no problem!
% legend() works, and legend(ax) works,
function results = func2(app)
% this function was added to the inside of the previous
% function, that's not right!
end
end
end
I just did find and replace legend to legend() and everything was fine.
(although best practice, i assume, would be to pass ax to the legend function)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by