Can anyone tell me why the function won't read the variables defined in the callback functions of this app?

1 vue (au cours des 30 derniers jours)
So I'm coding a simple app:
% Value changed function: DayDDEditField
function DayDDEditFieldValueChanged(app, event)
global DD
value = app.DayDDEditField.Value;
DD = value;
end
% Value changed function: MonthMMEditField
function MonthMMEditFieldValueChanged(app, event)
global MM
value = app.MonthMMEditField.Value;
MM = value;
end
% Value changed function: YearYYYYEditField
function YearYYYYEditFieldValueChanged(app, event)
global Y
value = app.YearYYYYEditField.Value;
Y = value;
end
% Value changed function: HourEditField
function HourEditFieldValueChanged(app, event)
global hour
value = app.HourEditField.Value;
hour = value;
end
% Value changed function: MinuteEditField
function MinuteEditFieldValueChanged(app, event)
global min
value = app.MinuteEditField.Value;
min = value;
end
% Value changed function: SecondEditField
function SecondEditFieldValueChanged(app, event)
global sec
value = app.SecondEditField.Value;
sec = value;
end
% Button pushed function: ConfirmButton
function ConfirmButtonPushed(app, event)
global DD MM Y
opts = 'non-modal';
year = num2str(Y);
ycheck1 = floor(Y/4);
ycheck2 = floor(Y/100);
ycheck3 = floor(Y/400);
if ((DD > 29) & (MM == 2))
errordlg('February has 29 days max', 'Error!', opts);
error('Error occurred!');
end
if ((ycheck2 == Y/100) & (ycheck3 ~= Y/400) & (DD == 29) & (MM == 2))
errordlg(['Year ' year ' is not bissextile therefore February does not have 29 days'], 'Error!', opts);
error('Error occurred!');
end
if ((DD == 29) & (MM == 2) & (ycheck1 ~= Y/4))
errordlg(['Year ' year ' is not bissextile therefore February does not have 29 days'], 'Error!', opts);
error('Error occurred!');
else
run('RightAscensionDate.m');
end
end
end
(I've not copied the starting and ending lines that app designer writes by itself, the grey ones). As you can see at the end I run this function:
function [] = RightAscensionDate()
% Function to evaluate the right ascension of the Greenwich Meridian at the
% time selected by the user.
global DD MM Y JD hour min sec alphadate omegarot
omegarot = 2*pi/(23*60*60 + 56*60 + 4);
JD = juliandate(Y,MM,DD, hour, min, sec);
T = (JD - 2415020)/36525;
alpha0 = (99.69083 + 36000.76892*T + 0.000387*T^2)*pi/180;
alphadate = alpha0 + omegarot*(hour*60*60 + min*60 + sec);
end
The problem is that the function doesn't seem to read the global variables (input arguments the user specifies in numeric fields in the UI figure) defined in the callback functions. I've checked and every time i push the "Confirm" button the function returns empty arrays of JD, T, alpha0 and alphadate, regardless of how I fill the numeric fields... Why does this happen?
  4 commentaires
Adam
Adam le 30 Nov 2018
At the top of your app file you will have a block something like this:
properties
...
end
Those are your class properties. By default they will be greyed out and contain the various ui components.
You are free to add any more you want though in another block, e.g.
properties( SetAccess = private, GetAccess = public )
hour;
min;
sec;
end
You can then set these in a callback simply as
app.hour = app.HourEditField.Value;
Even neater would be to use dependent properties, but that is more advanced so I won't suggest that!
Riccardo Basile
Riccardo Basile le 30 Nov 2018
Well... You've pretty much opened my eyes! Thanks a lot, I owe you one!

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by