Not able to run the app designer code.

11 Ansichten (letzte 30 Tage)
Kulbir
Kulbir am 16 Jun. 2023
Beantwortet: Kautuk Raj am 18 Jun. 2023
Hi all, i am trying to run app designer program. but could not succeded, it throwing the error always.
today4
Error using today4
Method 'registerApp' in class 'today4' uses different access permissions than its superclass
'matlab.apps.AppBase'. Set 'registerApp' access to 'protected' to match superclass.
The program that i have written is for GUI/APP for live real time plotting of audio signal.
classdef today4 < matlab.apps.AppBase
% Properties
properties (Access = private)
% GUI components
UIFigure
LiveAudioAxes
StartButton
StopButton
AudioObj
% Audio parameters
Fs
NumChannels
% Live plot variables
PlotInterval
PlotTimer
end
% App Designer callbacks
methods (Access = private)
% Button pushed function: StartButton
function StartButtonPushed(app, ~)
% Initialize audio input
app.AudioObj = audioDeviceReader(app.Fs, app.NumChannels);
% Create a timer for live plotting
app.PlotTimer = timer('TimerFcn', @(~,~) app.plotLiveData(),...
'Period', app.PlotInterval,...
'ExecutionMode', 'fixedRate');
% Start the timer
start(app.PlotTimer);
end
% Button pushed function: StopButton
function StopButtonPushed(app, ~)
% Stop the timer
stop(app.PlotTimer);
% Release the audio device
release(app.AudioObj);
end
% Close request function: UIFigure
function UIFigureCloseRequest(app, ~)
% Stop the timer
stop(app.PlotTimer);
% Delete the timer and release the audio device
delete(app.PlotTimer);
release(app.AudioObj);
% Delete the figure
delete(app);
end
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'Live Audio Plotter';
app.UIFigure.CloseRequestFcn = createCallbackFcn(app, @UIFigureCloseRequest, true);
% Create LiveAudioAxes
app.LiveAudioAxes = uiaxes(app.UIFigure);
title(app.LiveAudioAxes, 'Live Audio Signal')
xlabel(app.LiveAudioAxes, 'Time')
ylabel(app.LiveAudioAxes, 'Amplitude')
app.LiveAudioAxes.Position = [50 100 550 300];
% Create StartButton
app.StartButton = uibutton(app.UIFigure, 'push');
app.StartButton.Position = [200 50 100 22];
app.StartButton.Text = 'Start';
app.StartButton.ButtonPushedFcn = createCallbackFcn(app, @StartButtonPushed, true);
% Create StopButton
app.StopButton = uibutton(app.UIFigure, 'push');
app.StopButton.Position = [320 50 100 22];
app.StopButton.Text = 'Stop';
app.StopButton.ButtonPushedFcn = createCallbackFcn(app, @StopButtonPushed, true);
end
% Protected method: Register the app with MATLAB App Designer
function registerApp(app)
% Create and configure component properties
app.UIFigure.Visible = 'on';
app.UIFigure.Position = [100 100 640 480];
end
end
% Methods
methods (Access = protected)
% Plot live data
function plotLiveData(app)
% Read audio data
audioData = app.AudioObj();
% Plot audio signal
plot(app.LiveAudioAxes, audioData);
app.LiveAudioAxes.YLim = [-1 1];
drawnow;
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = today4(Fs, numChannels, plotInterval)
% Set audio parameters
app.Fs = Fs;
app.NumChannels = numChannels;
% Set plot interval
app.PlotInterval = plotInterval;
% Create and configure components
createComponents(app)
% Register the app with App Designer
app.registerApp();
if nargout == 0
clear app
end
end
% Code to display the app
function run(app)
if ~isdeployed
% Run the app
app.UIFigure.Visible = 'on';
end
end
end
end
  2 Kommentare
Image Analyst
Image Analyst am 16 Jun. 2023
If you have any more questions, then attach your .mlapp file and any data needed to read it in with the paperclip icon after you read this:
Kulbir
Kulbir am 16 Jun. 2023
Bearbeitet: Kulbir am 16 Jun. 2023
hello sir, thank you for the information. kindly find the attached file.
i am not able to run it. it's .m file. am trying to run it in the editor.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Kautuk Raj
Kautuk Raj am 18 Jun. 2023
The error you are encountering is because the registerApp method in your today4 class has different access permissions than the superclass matlab.apps.AppBase. The access permission of the registerApp method in the superclass is protected, so you need to match that in your subclass.
To fix the error, change the access permission of the registerApp method to protected.
Further, move the registerApp method inside the methods (Access = protected) block.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by