Unrecognized function or variable in APP DESIGNER
26 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jakub Snopl
le 4 Nov 2021
Modifié(e) : Jakub Snopl
le 3 Avr 2022
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 commentaires
Cris LaPierre
le 4 Nov 2021
What variable can't it find? Please share the complete error message (all the red text)
Réponse acceptée
Cris LaPierre
le 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)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!