Why am I keep getting "Unrecognized function or variable 'title'. " and "Variable might be used before it is defined" for dynamic title in app designer
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jay Coin
el 13 de Dic. de 2024
Comentada: Jay Coin
el 16 de Dic. de 2024
This is the code for the title:
title(app.UIAxes,['From ' char(cell2mat(app.PastMonthName)) ' of ' num2str(app.PastYear) ' to ' char(cell2mat(app.CurrentMonthName)) ' of ' num2str(app.CurrentYear) ' '], FontSize=20)
char(cell2mat(app.PastMonthName)) -------> results in "March"
num2str(app.PastYear) ------------------------------------> results in 2021
char(cell2mat(app.CurrentMonthName)) ------> results in "October"
num2str(app.CurrentYear) --------------------------------> results in 2022
This is the function Plotting(app) that the title() is in:
function Plotting(app)
if ConditionA
%code here etc etc
if ConditionA && ConditionPizza
%code here etc etc
if ConditionWood && ConditionA && ConditionPizza
%code here etc etc
if ConditionCelticsWillLose && ConditionWood && ConditionA && ConditionPizza
%code here etc etc
title(app.UIAxes,['From ' char(cell2mat(app.PastMonthName)) ' of ' num2str(app.PastYear) ' to ' char(cell2mat(app.CurrentMonthName)) ' of ' num2str(app.CurrentYear) ' '], FontSize=20)
end
end
end
end
end
I keep getting this error: "Variable might be used before it is defined"

The Command Window shoes a little bit more clarification: "Unrecognized function or variable 'title'."
Unrecognized function or variable 'title'.
Error in CSat_App/Plotting (line 201)
title(app.UIAxes,['% of Units Able to Successfully Transmit Data from ' char(cell2mat(app.PastMonthNameBU1)) ' ' num2str(app.PastMonthYearBU1) ' to ' char(cell2mat(app.CurrMonthNameBU1)) ' ' num2str(app.CurrMonthYearBU1) ' '],FontSize=20)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in CSat_App/ListBoxValueChanged (line 2642)
Plotting(app);
^^^^^^^^^^^^^
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 60)
newCallback = @(source, event)executeCallback(ams, ...
^^^^^^^^^^^^^^^^^^^^^^^^
Error while evaluating ListBox PrivateValueChangedFcn.
My ListBox PrivateValueChangedFcn is:
function ListBoxValueChanged(app, event)
app.ListBox.Items = vertcat({'All Customers'}, app.uniqueNummyNums);
app.valueFromListBox = app.ListBox.Value;
Plotting(app);
end
Community, do you have any suggestions as to how to resolve this?
I have no variable assigned to title(), so I am not understanding how the title() can be used before it is defined.
The dynamic variables, PastMonthName, CurrentMonthName, PastYear, and CurrentYear, are all defined early on in the startupFcn(app) way before Plotting(app) is stated. Plotting(app) is the last line of code in the startupFcn() as well as the ListBoxValueChanged(app,event) functions.
I am thinking that the 'event' input in ListBoxValueChanged(app,event) may be significant in some way, but I cannot see how.
1 comentario
Stephen23
el 14 de Dic. de 2024
"Community, do you have any suggestions as to how to resolve this?"
Get rid of the variable named "title".
Respuesta aceptada
Walter Roberson
el 13 de Dic. de 2024
Very likely, at some later point in the code you have an assignment to title . MATLAB "looks forward" and sees the eventual assignment, so it decides that "title" must be a variable for the purposes of the code, but at that point in the code the variable has not yet been defined.
Más respuestas (0)
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!