Effacer les filtres
Effacer les filtres

Import mat file in to App Designer

101 vues (au cours des 30 derniers jours)
dario cecchetti
dario cecchetti le 4 Mai 2018
Commenté : Asim Zaib le 21 Avr 2022
I would like import mat-file that contains some variables, but I can't load the file. Thanks for all.
% code
classdef app1_1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
TabGroup matlab.ui.container.TabGroup
Evporazione_annuale matlab.ui.container.Tab
UIAxes matlab.ui.control.UIAxes
Evaporazione_mensile matlab.ui.container.Tab
UIAxes2 matlab.ui.control.UIAxes
ANNILabel matlab.ui.control.Label
Lista_anni matlab.ui.control.DropDown
end
properties (Access = private)
load 'C:\Users\cecch\Documents\UNIVERSITA\Impianti Speciali Idraulici\Dati Portata\workspace_evaporazione.mat'
end
  1 commentaire
dario cecchetti
dario cecchetti le 15 Mai 2018
all very clear! thank you

Connectez-vous pour commenter.

Réponse acceptée

lokender Rawat
lokender Rawat le 15 Mai 2018
You can create a sample mat file named 'example.mat' with just four variables (a=1,b=2,c=3,d=[10 11 12 13]). Go to the 'Code View' and then add 'public property' like below to load the matlab file in your app. This 'var' variable is accessible to all other functions using 'app.var' and you can provide the variable name after that you want to access:
properties (Access = public)
var=load('\path_to_location\example.mat'); % specify the path to mat file
end
methods (Access = public)
function results = fun1(app)
results=app.var.d;
end
For results to appear, you can create a 'button' and 'text area' in the design view. Right click the 'button' and then select 'Go to ButtonPushed callback' and then on add the following code in the function callback:
app.TextArea.Value=num2str(fun1(app));
Once you run the app and click the button, you get the desired variable 'd' values in the 'text area'. I hope the above helps. You can refer the following documentation link and go over different sections of 'AppDesigner':
  2 commentaires
dario cecchetti
dario cecchetti le 15 Mai 2018
all very clear! thank you
Krystian Nowakowski
Krystian Nowakowski le 23 Avr 2020
Hi, thank you for the reply. I have another complication. I would like to pass to the app the path to the data file on the app startup. I don't know how to do it, because if I try to load in the startup function, then the variables are not accesible outside the startup function and there is no way to pass it to the section of the code that creates properties. Can you think of a solution to such a problem?

Connectez-vous pour commenter.

Plus de réponses (1)

Kunpeng Zhang
Kunpeng Zhang le 24 Nov 2019
How can I select a specific variable in the .mat file which contains different variables in the user interface? By 'text area' or what
  1 commentaire
Asim Zaib
Asim Zaib le 21 Avr 2022
example_matFile.mat.Variable_you_want_to_select

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!