How to write, Title of the Graph should be based on the input parameter values.

I have created an app, where the app starts with asking Number of Class Rooms to open. After opening 'n' number of Class rooms in tab group format, In each tab There are input parameters like Class room Number, Number of columns, Number of Benches for each column. After entering the classroom number, number of columns, and number of benches for each column, Import excel buttons are generated based on the value given in number of benches for each column. After reading the data from excel, a graph is generated in the tab and the title of the graph should be in the format like : Class room number (406)_Column(1)_Bench(1).

Réponses (1)

You didn't give us anything to work with about what the variables are, but formatting a string is simply
titlestring=compose("Classroom %d, Column %d Bench %d.",app.Classroom,app.Column,app.Bench);
title(titlestring)
The above needs to refer to the specific figure's data, of course.

5 commentaires

Let me attach the code, to get clarity about my question.
Shorten it down to the pertinent section and paste in the code here...trying download and run/debug a full app is more than folks have time for...
Where you create the plots you have to have the data available; use those variables there to create the dynamic title string...
Here is the code, Please do the necessary corrections:
classdef Class < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
NumberofClassesEditFieldLabel matlab.ui.control.Label
NumberofClassesEditField matlab.ui.control.NumericEditField
EnterButton matlab.ui.control.Button
end
properties (Access = private)
TabGroup
InputparameterButton
ClassroomLabel
Classroomeditfields
Classroomenter
ClassroomValues
Columnlabel
ColumneditFields
Columnenter
ColumnInputBoxes
Columnenter2
Numberofbenchesforeachcolumn
BenchInputBoxes
ValueColumn
Benchenter
BenchesforeachColumn
Importexcel
% Description
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: EnterButton
function EnterButtonPushed(app, event)
if ~isempty(app.TabGroup)
delete(app.TabGroup);
end
app.TabGroup = uitabgroup(app.UIFigure, 'Position', [20 70 1800 800]);
numTabs = app.NumberofClassesEditField.Value;
app.Classroomeditfields = gobjects(1,numTabs);
app.ColumneditFields = gobjects(1,numTabs);
app.ColumnInputBoxes = gobjects(1,numTabs);
app.Importexcel = gobjects(1,numTabs);
for i = 1:numTabs
tab = uitab(app.TabGroup,'Title',['Classroom' num2str(i)]);
app.InputparameterButton = uibutton(tab,'Text','Click To enter Input parameters','Position',[30, 735, 250, 22],...
"ButtonPushedFcn",@(btn,event) InputparameterButtonPushed(app,tab,i));
end
app.ColumnInputBoxes = cell(1,numTabs);
app.BenchInputBoxes = cell(1,numTabs);
app.Importexcel = cell(1,numTabs);
end
function InputparameterButtonPushed(app, tab, Classroom)
app.ClassroomLabel(Classroom) = uilabel(tab, 'Text', 'Classroom:', ...
'Position', [30, 705, 100, 22]);
app.Classroomeditfields(Classroom) = uieditfield(tab, 'numeric','Limits',[0 100],...
'Position', [130, 705, 100, 22]);
app.Classroomenter(Classroom) = uibutton(tab, 'push', ...
'Position', [250, 705, 100, 22], ...
'Text', 'Enter', ...
'ButtonPushedFcn', @(btn,event) classroomenterButtonPushed(app, tab, Classroom));
end
function classroomenterButtonPushed(app, tab, Classroom)
app.ClassroomValues = zeros (1,Classroom);
app.ClassroomValues = app.Classroomeditfields(Classroom).Value;
disp(app.ClassroomValues)
app.Columnlabel(Classroom) = uilabel(tab,'Text', 'Number of Columns:', ...
'Position', [30, 675, 200, 22]);
app.ColumneditFields(Classroom) = uieditfield(tab, 'numeric',...
'RoundFractionalValues','on', ...
'Limits', [0,100], ...
'Position', [130, 675, 100, 22]);
app.Columnenter(Classroom) = uibutton(tab, 'push', ...
'Position', [250, 675, 100, 22], ...
'Text', 'Enter', ...
'ButtonPushedFcn', @(btn,event) ColumnenterButtonPushed(app, tab, Classroom));
end
function ColumnenterButtonPushed(app, tab, Classroom)
if ~isempty(app.ColumnInputBoxes{Classroom})
delete(app.ColumnInputBoxes{Classroom});
end
numColumnBoxes = app.ColumneditFields(Classroom).Value;
app.ColumnInputBoxes{Classroom} = gobjects(1,numColumnBoxes);
app.ColumnInputBoxes = cell(1, numColumnBoxes);
initialPosition = [30, 645, 60, 22];
for j = 1:numColumnBoxes
fieldPosition = initialPosition +[(j-1)*70, 0, 0, 0];
app.ColumnInputBoxes{Classroom}(j) = uieditfield(tab, 'numeric',...
'Limits', [0,100],...
'Position', fieldPosition);
end
if numColumnBoxes < 1
uialert(app.UIFigure, 'Please enter a positive number', 'Input Error');
return;
end
app.Columnenter2(Classroom) = uibutton(tab, 'push', ...
'Position', [130, 615, 100, 22], ...
'Text', 'Enter', ...
'ButtonPushedFcn', @(btn,event) Columnenter2ButtonPushed(app,tab,Classroom));
end
function Columnenter2ButtonPushed(app,tab,Classroom)
app.Numberofbenchesforeachcolumn(Classroom) = uilabel(tab, ...
'Text', 'Number of Benches for each Column:', ...
'Position', [30, 585, 300, 22]);
if ~isempty(app.BenchInputBoxes{Classroom})
delete(app.BenchInputBoxes{Classroom});
end
numColumnBoxes=app.ColumneditFields(Classroom).Value;
app.BenchInputBoxes{Classroom} = gobjects(1,numColumnBoxes);
initialPosition = [30, 555, 50, 22];
for k = 1:numColumnBoxes
fieldPosition = initialPosition +[(k-1)*70, 0, 0, 0];
app.BenchInputBoxes{Classroom}(k) = uieditfield(tab, 'numeric','Limits', [0,100],...
'RoundFractionalValues','on','Position', fieldPosition);
end
app.ValueColumn = zeros(1, numColumnBoxes);
% Loop through each box to get the value
for j = 1:numColumnBoxes
app.ValueColumn(j) = app.ColumnInputBoxes{Classroom}(j).Value;
end
disp(app.ValueColumn)
app.Benchenter(Classroom) = uibutton(tab, 'push', ...
'Position', [130,525,100,22], ...
'Text', 'Enter', ...
'ButtonPushedFcn', @(btn,event) BenchenterButtonPushed(app, tab, Classroom));
if app.ValueColumn < 1
uialert(app.UIFigure, 'Please enter a positive number', 'Input Error');
return;
end
end
function BenchenterButtonPushed(app, tab, Classroom)
app.BenchesforeachColumn(Classroom) = uilabel(tab, ...
'Text', 'Benches for each Column:', ...
'Position', [30, 495, 350, 22]);
if ~isempty(app.Importexcel{Classroom})
delete(app.Importexcel{Classroom});
end
numColumnBoxes = app.ColumneditFields(Classroom).Value;
app.Importexcel{Classroom} = cell(1,numColumnBoxes);
initialPosition = [30, 475, 50, 22];
for m = 1:numColumnBoxes
rowposition = initialPosition + [(m-1)*70,0,0,0];
numBenches = app.BenchInputBoxes{Classroom}(m).Value;
app.Importexcel{Classroom,m} = gobjects(1,numBenches);
for n = 1:numBenches
columnposition = rowposition + [0,-(n)*30, 0, 0];
app.Importexcel{Classroom,m}(n) = uibutton(tab, 'push', ...
'Position', columnposition , ...
'Text', 'Imp.Excel', ...
'ButtonPushedFcn', @(btn,event) ImportexcelButtonPushed(app, Classroom, n));
end
end
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 863 764];
app.UIFigure.Name = 'MATLAB App';
app.UIFigure.Scrollable = 'on';
app.UIFigure.WindowState = 'maximized';
% Create NumberofClassesEditFieldLabel
app.NumberofClassesEditFieldLabel = uilabel(app.UIFigure);
app.NumberofClassesEditFieldLabel.Position = [85 46 114 22];
app.NumberofClassesEditFieldLabel.Text = 'Number of Classes :';
% Create NumberofClassesEditField
app.NumberofClassesEditField = uieditfield(app.UIFigure, 'numeric');
app.NumberofClassesEditField.Position = [229 46 55 22];
% Create EnterButton
app.EnterButton = uibutton(app.UIFigure, 'push');
app.EnterButton.ButtonPushedFcn = createCallbackFcn(app, @EnterButtonPushed, true);
app.EnterButton.Position = [299 46 100 22];
app.EnterButton.Text = 'Enter';
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = Class
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
dpb
dpb le 24 Sep 2024
Modifié(e) : dpb le 24 Sep 2024
Pare it down to the pertinent area you are having trouble with and explain what your specific problem is in doing what you wish...90% of the code you're expecting somebody to wade through and try to decipher is totally immaterial to the question...
Just looking through the code, I don't see anything that would create the figure(s) you want labelled, to begin with; there's the code that would be pertinent, it would appear.
If the code generated by an AI bot does not produce the expected results, you may have difficulty pinpointing the lines causing issues. In that case, I recommend clearly describing in words what you want to design or include in the app. Additionally, please create a sketch of the app interface that indicates how you would like the "Title of the Graph" to be displayed in the figure.
Most human programmers do not annotate or comment on the obvious purpose of certain commands, and bots tend to use "space," while human code is generally cluttered and not easily readable by others.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Develop Apps Programmatically dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by