Clear Filters
Clear Filters

whats wrong in the for loop in my app?

1 view (last 30 days)
Muazma Ali
Muazma Ali on 25 Feb 2024
Answered: Eric Delgado on 1 Apr 2024
type visualiseringsapp2_1.mlapp
classdef visualiseringsapp2_1 < matlab.apps.AppBase % Properties that correspond to app components properties (Access = public) UIFigure matlab.ui.Figure UITable matlab.ui.control.Table OsmoticdataresultsforallzonesLabel matlab.ui.control.Label ReadresultsLabel matlab.ui.control.Label Switch matlab.ui.control.Switch UIAxes matlab.ui.control.UIAxes end properties (Access = public) Callingapp end methods (Access = private) % Code that executes after component creation function startupFcn(app, app2, app3) app.Callingapp = app3; end % Value changed function: Switch function SwitchValueChanged(app, event) value = app.Switch.Value; if strcmpi(value,'on') osmotic_data_table=readtable('Osmotic_data.xls', "Sheet", 1); app.UITable.Data=osmotic_data_table; app.UITable.ColumnName= osmotic_data_table.Properties.VariableNames; x=table2array( osmotic_data_table(:,"Total_water_activity")); y=table2array( osmotic_data_table(:,"Osmotic_pressure")); plot(app.UIAxes,x,y) end for i = 1:app.Callingapp.antall_soner if Osmotic_pressure(i)<100 effect='Not benefical'; elseif Osmotic_pressure(i)>=100&&Osmotic_pressure(i)<120 effect='Intermediate'; else effect='Benefical'; end end app.UITable.Data=[osmotic_data_table effect]; end end % App initialization and construction methods (Access = private) % Create UIFigure and components function createComponents(app) % Create UIFigure app.UIFigure = uifigure; app.UIFigure.Position = [100 100 640 480]; app.UIFigure.Name = 'UI Figure'; % Create UITable app.UITable = uitable(app.UIFigure); app.UITable.ColumnName = {'Column 1'; 'Column 2'; 'Column 3'; 'Column 4'}; app.UITable.RowName = {}; app.UITable.Position = [15 254 426 185]; % Create OsmoticdataresultsforallzonesLabel app.OsmoticdataresultsforallzonesLabel = uilabel(app.UIFigure); app.OsmoticdataresultsforallzonesLabel.BackgroundColor = [0 1 1]; app.OsmoticdataresultsforallzonesLabel.FontWeight = 'bold'; app.OsmoticdataresultsforallzonesLabel.Position = [15 450 426 22]; app.OsmoticdataresultsforallzonesLabel.Text = ' Osmotic data results for all zones'; % Create ReadresultsLabel app.ReadresultsLabel = uilabel(app.UIFigure); app.ReadresultsLabel.FontWeight = 'bold'; app.ReadresultsLabel.Position = [121 215 78 22]; app.ReadresultsLabel.Text = 'Read results'; % Create Switch app.Switch = uiswitch(app.UIFigure, 'slider'); app.Switch.ValueChangedFcn = createCallbackFcn(app, @SwitchValueChanged, true); app.Switch.Position = [242 217 45 20]; % Create UIAxes app.UIAxes = uiaxes(app.UIFigure); title(app.UIAxes, 'Total water activity versus osmotic pressure') xlabel(app.UIAxes, 'Activity') ylabel(app.UIAxes, 'Osmotic_ pressure') app.UIAxes.YTickLabel = {'0'; '50'; '100'; '150'; '200'; '250'; '300'; '350'; '400'; '450'; '.500'; '1'}; app.UIAxes.XGrid = 'on'; app.UIAxes.YGrid = 'on'; app.UIAxes.Position = [15 10 426 185]; end end methods (Access = public) % Construct app function app = visualiseringsapp2_1(varargin) % Create and configure components createComponents(app) % Register the app with App Designer registerApp(app, app.UIFigure) % Execute the startup function runStartupFcn(app, @(app)startupFcn(app, varargin{:})) 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
I have a for loop in visualiseringsapp 2_1 , there is something wrong in it I think
I am gettin this error message when I run the app:
Error using visualiseringsapp2_1/startupFcn (line 23)
Not enough input arguments.
Error in visualiseringsapp2_1 (line 115)
runStartupFcn(app, @(app)startupFcn(app, varargin{:}))
Error in app3/DisplayallresultsButtonPushed (line 1855)
visualiseringsapp2_1(app)
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.
Dot indexing is not supported for variables of this type.
Error in visualiseringsapp2_1/SwitchValueChanged (line 42)
for i = 1:app.Callingapp.antall_soner
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 378)
Error while evaluating Switch PrivateValueChangedFcn.
.......
I have declared app2 as the input argument in my startup for visualiseringsapp2_1 because it is using the public property from app2 (called antall_soner), and the callingapp is app 3 . ( meaning the visualiseringsapp2_1 is called from app3), as you can see.

Answers (1)

Eric Delgado
Eric Delgado on 1 Apr 2024
My first piece of advice is: try to assign meaningful names to your applications. Names like 'app2', 'app3', and 'visualiseringsapp2_1' are definitely not helpful! :)
So, if I understood correctly, you're calling 'visualiseringsapp2_1' from 'app3', and you're trying to pass the handles of 'app2' and 'app3' to 'visualiseringsapp2_1'. Inside 'visualiseringsapp2_1', you have a startup function like this:
startupFcn(app, app2, app3)
The error messages was: "Not enough input arguments."
When you push a button, in "app3", you are calling:
visualiseringsapp2_1(app)
But look... you are not passing two arguments, but one! If you intend to keep 'app2' and 'app3' as arguments for your 'visualiseringsapp2_1' app, in this order, then your call (inside 'app3') should look something like this:
visualiseringsapp2_1(app.app2Handle, app)
Notice that since you want to pass the handle of 'app2' to 'visualiseringsapp2_1', it's a good idea to store its handle as a property of 'app3'. Below changes that you have to make...
%% Changes in "app3.mlapp"
properties (Access = public)
App2Handle
end
% DisplayallresultsButtonPushed
visualiseringsapp2_1(app.App2Handle, app)
%% Changes in "visualiseringsapp2_1.mlapp"
% Create a property for each handle...
properties (Access = public)
App2Handle
App3Handle
end
function startupFcn(app, app2, app3)
app.App2Handle = app2;
app.App3Handle = app3;
end
% And replace app.Callingapp.antall_soner for app.App2Handle.antall_soner

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!