Clear Filters
Clear Filters

Unrecognized function or variable in APP DESIGNER

36 views (last 30 days)
Hi,
when I push Vypocet_Button i my app, it calculates points of great circle on sphere. And I need to use these results, when I push another ProtokolButton (it should generate .txt with results). The problem is that, the app does not have in memory values calculated after pushing first button (Unrecognized function or variable). I tried to use Properties, but with no result...
% Button pushed function: Vypocet_Button
function Vypocet_ButtonPushed(app, event)
Ua_D = app.VychBod_U_stupen.Value;
Ua_M = app.VychBod_U_minuta.Value;
Ua_S = app.VychBod_U_vterina.Value;
Va_D = app.VychBod_V_stupen.Value;
Va_M = app.VychBod_V_minuta.Value;
Va_S = app.VychBod_V_vterina.Value;
Ub_D = app.KoncBod_U_stupen.Value;
Ub_M = app.KoncBod_U_minuta.Value;
Ub_S = app.KoncBod_U_vterina.Value;
Vb_D = app.KoncBod_V_stupen.Value;
Vb_M = app.KoncBod_V_minuta.Value;
Vb_S = app.KoncBod_V_vterina.Value;
R = app.PolomrkoulemEditField.Value;
poc = app.PoetmezilehlchbodEditField.Value;
Ua = deg2rad(Ua_D + Ua_M/60 + Ua_S/3600);
Va = deg2rad(Va_D + Va_M/60 + Va_S/3600);
Ub = deg2rad(Ub_D + Ub_M/60 + Ub_S/3600);
Vb = deg2rad(Vb_D + Vb_M/60 + Vb_S/3600);
% ortodroma
V_orto_int = (Vb-Va)/poc; % pravidelne deleni intevalu vymezeneho zemepisnymi delkami bodu A a B
V_orto = Va:V_orto_int:Vb; % vektor zem.delek boduu ortodromy
l_orto = acos(cos(pi/2-Ua)*cos(pi/2-Ub) + sin(pi/2-Ua)*sin(pi/2-Ub)*cos(Vb-Va)); % delka orodromy
azi_orto = asin((cos(Ub)*sin(Vb-Va)) / (sin(l_orto))); % azimut na prvnim bode
U_orto = Ua;
for i = 1:length(V_orto)-1 %vypocet zem. sirek jednotlivych bodu
alfa(i) = acos(-cos(azi_orto(i))*cos(V_orto_int) + sin(azi_orto(i))*sin(V_orto_int)*cos(pi/2 - U_orto(i)));
azi_orto(i+1) = pi - alfa(i);
U_orto(i+1) = pi/2 - asin((sin(pi/2 - U_orto(i))*sin(azi_orto(i))) / (sin(alfa(i))));
end
U_orto = degrees2dms(rad2deg(U_orto)); % prevod na stupne
V_orto = degrees2dms(rad2deg(V_orto));
end
% Button pushed function: ProtokolButton
function ProtokolButtonPushed(app, event)
hlavicka1 = '---------SOURADNICE BODU ORTODROMY---------';
hlavicka2 = 'c.b. U[D M S] V[D M S]';
cb = 1:poc+1 ;
fileID = fopen('vysledky.txt','w');
fprintf(fileID,'%s\n',hlavicka1);
fprintf(fileID,'%s\n',hlavicka2);
fprintf(fileID,'%2d %8d %4d %7.3f %8d %4d %7.3f\n',[cb; U_orto(:,1)'; U_orto(:,2)'; U_orto(:,3)';V_orto(:,1)'; V_orto(:,2)'; V_orto(:,3)']);
fprintf(fileID,'delka ortodromy = %.3f m\n',l_orto)
fprintf(fileID,'%s\n',' ')
end
end
  2 Comments
Cris LaPierre
Cris LaPierre on 4 Nov 2021
What variable can't it find? Please share the complete error message (all the red text)
Jakub Snopl
Jakub Snopl on 4 Nov 2021
Unrecognized function or variable 'poc'.
Error in App_KartoZobraz_update_031121/ProtokolButtonPushed (line 225)
cb = 1:poc+1 ;
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 410)
Error while evaluating Button PrivateButtonPushedFcn.

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 4 Nov 2021
Keep in mind variable scope. Variables created inside a function are destroyed as soon as the function ends. You need to add those variables you want to access in another callback to the apps structure. You do this my listing them as app properties, and then assigning to and accessing them by prepending them with 'app.'. See the 'Share Data Within App Designer Apps' page.
For example
app.l_orto = acos(cos(pi/2-Ua)*cos(pi/2-Ub) + sin(pi/2-Ua)*sin(pi/2-Ub)*cos(Vb-Va)); % delka orodromy
...
fprintf(fileID,'delka ortodromy = %.3f m\n',app.l_orto)

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!