Clear Filters
Clear Filters

pass data from app designer to .m file

4 views (last 30 days)
Hasan Abbas
Hasan Abbas on 27 Dec 2020
Commented: Hasan Abbas on 27 Dec 2020
I have a code was written in a .m file (the code below), i need to get the value of some parameters from another app that is created in app designer
i called the .m file in push button callback
the parameters i want to get are:
L
LOD
N
T_GMT
Step
so i write these valuse in edit field and return them to .m file
L=33; %Latitude
LOD=44; %Longitude
N=90; %day number
T_GMT=3; %Time difference with reference to GMT
Step=60; %step each hour
Ds=23.45*sin((360*(N-81)/365)*(pi/180)); % angle of
B=(360*(N-81))/364; %Equation of time
EoT=(9.87*sin(2*B*pi/180))- (7.53*cos(B*pi/180))- (1.5*sin(B*pi/180)); %Equation of time
Lzt= 15* T_GMT; %LMST
if LOD>=0
Ts_correction= (-4*(Lzt-LOD))+EoT; %solar time correction
else
Ts_correction= (4*(Lzt-LOD))+EoT; %solar time correction
end
Wsr_ssi=- tan(Ds*pi/180)*tan(L*pi/180); %Sunrise/Sunset
Wsrsr_ss=acosd(Wsr_ssi); %Sunrise/Sunset hour angle
ASTsr=abs((((Wsrsr_ss/15)-12)*60)); %Sunrise solar time
ASTss=(((Wsrsr_ss/15)+12)*60); %Sunset solar time
Tsr=ASTsr+abs(Ts_correction); %Actual Sunrise time
Tss=ASTss+abs(Ts_correction); %Actual Sunset time
sin_Alpha=[];
for LMT=Tsr:Step:Tss %for loop for the day time
Ts= LMT + Ts_correction; %solar time at each step
Hs=(15 *(Ts - (12*60)))/60; %hour angle at each step
sin_Alpha_i=(sin(L*pi/180)*sin(Ds*pi/180))+(cos(L*pi/180)*cos(Ds*pi/180)* cos(Hs*pi/180)); %altitudeangle
sin_Alpha=[sin_Alpha;sin_Alpha_i]; % store altitude
end
LMT=Tsr:Step:Tss;
sin_Alpha;
Go=1367; %solar constant
Gext=Go*(1+(0.0333*cos(360*N/365))); %available Gext
GextH=Gext*sin_Alpha; %Gex on horizontal surface
plot(LMT,GextH) %plot results

Answers (1)

Rik
Rik on 27 Dec 2020
The easy solution is to never use scripts for importants things. Put the code in a function so you can call it from anywhere, including an AppDesigner callback.
Don't forget to write comments that describe what the code is doing. You will not understand this in a year.
function [LMT,GextH]=your_function_name(L,LOD,N,T_GMT,Step)
%One line description goes here
%
%full explanation of what this function does goes here
%set up default values
if nargin<1
L=33; %Latitude
end
if nargin<2
LOD=44; %Longitude
end
if nargin<3
N=90; %day number
end
if nargin<4
T_GMT=3; %Time difference with reference to GMT
end
if nargin<5
Step=60; %step each hour
end
Ds=23.45*sin((360*(N-81)/365)*(pi/180)); % angle of
B=(360*(N-81))/364; %Equation of time
EoT=(9.87*sin(2*B*pi/180))- (7.53*cos(B*pi/180))- (1.5*sin(B*pi/180)); %Equation of time
Lzt= 15* T_GMT; %LMST
if LOD>=0
Ts_correction= (-4*(Lzt-LOD))+EoT; %solar time correction
else
Ts_correction= (4*(Lzt-LOD))+EoT; %solar time correction
end
Wsr_ssi=- tan(Ds*pi/180)*tan(L*pi/180); %Sunrise/Sunset
Wsrsr_ss=acosd(Wsr_ssi); %Sunrise/Sunset hour angle
ASTsr=abs((((Wsrsr_ss/15)-12)*60)); %Sunrise solar time
ASTss=(((Wsrsr_ss/15)+12)*60); %Sunset solar time
Tsr=ASTsr+abs(Ts_correction); %Actual Sunrise time
Tss=ASTss+abs(Ts_correction); %Actual Sunset time
sin_Alpha=[];
for LMT=Tsr:Step:Tss %for loop for the day time
Ts= LMT + Ts_correction; %solar time at each step
Hs=(15 *(Ts - (12*60)))/60; %hour angle at each step
sin_Alpha_i=(sin(L*pi/180)*sin(Ds*pi/180))+(cos(L*pi/180)*cos(Ds*pi/180)* cos(Hs*pi/180)); %altitudeangle
sin_Alpha=[sin_Alpha;sin_Alpha_i]; % store altitude
end
LMT=Tsr:Step:Tss;
sin_Alpha;
%^^^^^^^^
% what is this doing? sin_Alpha is a variable, so this will not do anything (because the ; will supress the printing)
Go=1367; %solar constant
Gext=Go*(1+(0.0333*cos(360*N/365))); %available Gext
GextH=Gext*sin_Alpha; %Gex on horizontal surface
end
  5 Comments
Rik
Rik on 27 Dec 2020
You shouldn't need to search: you can use the examples I posted here. Let me know if you need help anyway.
Hasan Abbas
Hasan Abbas on 27 Dec 2020
ok, i will try it and tell you if i have any problem with it
thanks again

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!