How to properly import excel data, insert values through "EDIT FIELD" and run a function using App Designer in Matlab?

9 次查看(过去 30 天)
Hi everybody!
I'm trying to create a GUI that open an .xlsx file, importing the table as a matrix called "data". Then I want to manually insert values by "Edit field (numeric)". These values should be matrixes, called: SM, SRT, beta, LAT. Once I have uploaded all these matrixes I want to run the main function using the button RUN. The problem is that I don't see anything uploading as matrixes, so the function gives me the error " NOT ENOUGHT INPUT ARGUMENTS".
Any helps?
THANKS IN ADVANCE :) !!
classdef prova_app < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
LoaddataButton matlab.ui.control.Button
RUNButton matlab.ui.control.Button
LatitudeEditFieldLabel matlab.ui.control.Label
LatitudeEditField matlab.ui.control.NumericEditField
FieldcapacitymmEditFieldLabel matlab.ui.control.Label
FieldcapacitymmEditField matlab.ui.control.NumericEditField
SnowfallrainfallthresholdCEditFieldLabel matlab.ui.control.Label
SnowfallrainfallthresholdCEditField matlab.ui.control.NumericEditField
betaEditFieldLabel matlab.ui.control.Label
betaEditField matlab.ui.control.NumericEditField
UITable matlab.ui.control.Table
end
methods (Access = private)
% Button pushed function: LoaddataButton
function LoaddataButtonPushed(app, event)
[file, path] = uigetfile('*.xlsx');
data = readtable(fullfile(path, file));
app.UITable.Data = data;
app.UITable.ColumnName = data.Properties.VariableNames;
end
% Button pushed function: RUNButton
function RUNButtonPushed(app, event)
LAT = app.LatitudeEditField.Value;
SM = app.FieldcapacitymmEditField.Value;
beta = app.betaEditField.Value;
SRT = app.SnowfallrainfallthresholdCEditField.Value;
out = thorntwMater(data,LAT,SM,beta,SRT);
% out = thorntwMater(app.LoaddataButton,app.LatitudeEditField,app.FieldcapacitymmEditField,app.SnowfallrainfallthresholdCEditField,app.betaEditField)
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 LoaddataButton
app.LoaddataButton = uibutton(app.UIFigure, 'push');
app.LoaddataButton.ButtonPushedFcn = createCallbackFcn(app, @LoaddataButtonPushed, true);
app.LoaddataButton.Position = [271 218 100 22];
app.LoaddataButton.Text = 'Load data';
% Create RUNButton
app.RUNButton = uibutton(app.UIFigure, 'push');
app.RUNButton.ButtonPushedFcn = createCallbackFcn(app, @RUNButtonPushed, true);
app.RUNButton.Position = [271 31 100 22];
app.RUNButton.Text = 'RUN';
% Create LatitudeEditFieldLabel
app.LatitudeEditFieldLabel = uilabel(app.UIFigure);
app.LatitudeEditFieldLabel.HorizontalAlignment = 'right';
app.LatitudeEditFieldLabel.Position = [56 174 64 22];
app.LatitudeEditFieldLabel.Text = 'Latitude (°)';
% Create LatitudeEditField
app.LatitudeEditField = uieditfield(app.UIFigure, 'numeric');
app.LatitudeEditField.Position = [135 174 100 22];
% Create FieldcapacitymmEditFieldLabel
app.FieldcapacitymmEditFieldLabel = uilabel(app.UIFigure);
app.FieldcapacitymmEditFieldLabel.HorizontalAlignment = 'right';
app.FieldcapacitymmEditFieldLabel.Position = [352 174 109 22];
app.FieldcapacitymmEditFieldLabel.Text = 'Field capacity [mm]';
% Create FieldcapacitymmEditField
app.FieldcapacitymmEditField = uieditfield(app.UIFigure, 'numeric');
app.FieldcapacitymmEditField.Position = [476 174 100 22];
% Create SnowfallrainfallthresholdCEditFieldLabel
app.SnowfallrainfallthresholdCEditFieldLabel = uilabel(app.UIFigure);
app.SnowfallrainfallthresholdCEditFieldLabel.HorizontalAlignment = 'right';
app.SnowfallrainfallthresholdCEditFieldLabel.Position = [-8 95 166 22];
app.SnowfallrainfallthresholdCEditFieldLabel.Text = 'Snowfall rainfall threshold [°C]';
% Create SnowfallrainfallthresholdCEditField
app.SnowfallrainfallthresholdCEditField = uieditfield(app.UIFigure, 'numeric');
app.SnowfallrainfallthresholdCEditField.Position = [172 95 100 22];
% Create betaEditFieldLabel
app.betaEditFieldLabel = uilabel(app.UIFigure);
app.betaEditFieldLabel.HorizontalAlignment = 'right';
app.betaEditFieldLabel.Position = [432 95 29 22];
app.betaEditFieldLabel.Text = 'beta';
% Create betaEditField
app.betaEditField = uieditfield(app.UIFigure, 'numeric');
app.betaEditField.Position = [476 95 100 22];
% Create UITable
app.UITable = uitable(app.UIFigure);
app.UITable.ColumnName = {'Column 1'; 'Column 2'; 'Column 3'; 'Column 4'};
app.UITable.RowName = {};
app.UITable.Position = [170 257 302 185];
end
end
methods (Access = public)
% Construct app
function app = prova_app
% Create and configure 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

回答(1 个)

Cameron B
Cameron B 2020-4-2
What is this
output = thorntwMater()
You have nothing as the input arguements so that's the error it's going to throw.
  2 个评论
EM geo
EM geo 2020-4-3
@Cameron B thank you for your reply. Yes, i tried to insert the input variables, which are the ones created before: SM, LAT, SRT, beta, data. I get this error: Undefined function or variable 'data'. It seems MATLAB doesn't recognised the variable data, which is extracted by the excel file in this way:
function load_dataPushed(app, event)
[file, path] = uigetfile('*.xlsx');
data = readtable(fullfile(path, file));
app.UITable.Data = data;
app.UITable.ColumnName = data.Properties.VariableNames;
end
Cameron B
Cameron B 2020-4-3
Just so we're clear - what you're saying is that when you click the RUN button, it gives the error right? If so, that means whatever the function attached to the RUNButtonPushed callback is what is giving you trouble. That means that this
output = thorntwMater()
is not correct. Can you post whatever function thorntwMater() is so we can figure out what the inputs need to be? Or can you at least tell us what the inputs to the function are? We can't help you without that information.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by