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
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
2020년 4월 23일
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
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!