This video shows the steps to pass the value of input variable from one tab to another in the UI of Matlab app designer. This demo is show in MATLAB R2023a. However, it will be applicable for other versions of MATLAB as well.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
Complete source code and other details:
Main Methods:
% Callbacks that handle component events
methods (Access = private)
% Value changed function: InputValueTab1EditField
function InputValueTab1EditFieldValueChanged(app, event)
value = app.InputValueTab1EditField.Value;
app.InputValueTab1CopiedEditField.Value = value;
end
% Value changed function: InputValueTab2EditField
function InputValueTab2EditFieldValueChanged(app, event)
value = app.InputValueTab2EditField.Value;
app.InputValueTab2CopiedEditField.Value = value;
end
end
Complete Code
classdef TabsValuesAppDesigner < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
TabGroup matlab.ui.container.TabGroup
Tab1 matlab.ui.container.Tab
InputValueTab2CopiedEditField matlab.ui.control.EditField
InputValueTab2CopiedEditFieldLabel matlab.ui.control.Label
InputValueTab1EditField matlab.ui.control.EditField
InputValueTab1EditFieldLabel matlab.ui.control.Label
Tab2 matlab.ui.container.Tab
InputValueTab1CopiedEditField matlab.ui.control.EditField
InputValueTab1CopiedEditFieldLabel matlab.ui.control.Label
InputValueTab2EditField matlab.ui.control.EditField
InputValueTab2EditFieldLabel matlab.ui.control.Label
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: InputValueTab1EditField
function InputValueTab1EditFieldValueChanged(app, event)
value = app.InputValueTab1EditField.Value;
app.InputValueTab1CopiedEditField.Value = value;
end
% Value changed function: InputValueTab2EditField
function InputValueTab2EditFieldValueChanged(app, event)
value = app.InputValueTab2EditField.Value;
app.InputValueTab2CopiedEditField.Value = value;
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 640 480];
app.UIFigure.Name = 'MATLAB App';
% Create TabGroup
app.TabGroup = uitabgroup(app.UIFigure);
app.TabGroup.Position = [2 1 639 480];
% Create Tab1
app.Tab1 = uitab(app.TabGroup);
app.Tab1.Title = 'Tab1';
% Create InputValueTab1EditFieldLabel
app.InputValueTab1EditFieldLabel = uilabel(app.Tab1);
app.InputValueTab1EditFieldLabel.HorizontalAlignment = 'right';
app.InputValueTab1EditFieldLabel.Position = [42 364 94 22];
app.InputValueTab1EditFieldLabel.Text = 'Input Value Tab1';
% Create InputValueTab1EditField
app.InputValueTab1EditField = uieditfield(app.Tab1, 'text');
app.InputValueTab1EditField.ValueChangedFcn = createCallbackFcn(app, @InputValueTab1EditFieldValueChanged, true);
app.InputValueTab1EditField.Position = [151 364 361 22];
% Create InputValueTab2CopiedEditFieldLabel
app.InputValueTab2CopiedEditFieldLabel = uilabel(app.Tab1);
app.InputValueTab2CopiedEditFieldLabel.HorizontalAlignment = 'right';
app.InputValueTab2CopiedEditFieldLabel.Position = [12 260 135 22];
app.InputValueTab2CopiedEditFieldLabel.Text = 'Input Value Tab2 Copied';
% Create InputValueTab2CopiedEditField
app.InputValueTab2CopiedEditField = uieditfield(app.Tab1, 'text');
app.InputValueTab2CopiedEditField.Position = [162 260 383 22];
% Create Tab2
app.Tab2 = uitab(app.TabGroup);
app.Tab2.Title = 'Tab2';
% Create InputValueTab2EditFieldLabel
app.InputValueTab2EditFieldLabel = uilabel(app.Tab2);
app.InputValueTab2EditFieldLabel.HorizontalAlignment = 'right';
app.InputValueTab2EditFieldLabel.Position = [30 364 94 22];
app.InputValueTab2EditFieldLabel.Text = 'Input Value Tab2';
% Create InputValueTab2EditField
app.InputValueTab2EditField = uieditfield(app.Tab2, 'text');
app.InputValueTab2EditField.ValueChangedFcn = createCallbackFcn(app, @InputValueTab2EditFieldValueChanged, true);
app.InputValueTab2EditField.Position = [139 364 383 22];
% Create InputValueTab1CopiedEditFieldLabel
app.InputValueTab1CopiedEditFieldLabel = uilabel(app.Tab2);
app.InputValueTab1CopiedEditFieldLabel.HorizontalAlignment = 'right';
app.InputValueTab1CopiedEditFieldLabel.Position = [43 260 135 22];
app.InputValueTab1CopiedEditFieldLabel.Text = 'Input Value Tab1 Copied';
% Create InputValueTab1CopiedEditField
app.InputValueTab1CopiedEditField = uieditfield(app.Tab2, 'text');
app.InputValueTab1CopiedEditField.Position = [193 260 361 22];
% 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 = TabsValuesAppDesigner
% 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
Screenshots: