Import mat file in to App Designer

97 次查看(过去 30 天)
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

采纳的回答

lokender Rawat
lokender Rawat 2018-5-15
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 个评论
Krystian Nowakowski
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?

请先登录,再进行评论。

更多回答(1 个)

Kunpeng Zhang
Kunpeng Zhang 2019-11-24
How can I select a specific variable in the .mat file which contains different variables in the user interface? By 'text area' or what

Community Treasure Hunt

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

Start Hunting!