operands to the and && operators must be convertible to logical scalar values. This error appears in app designer. Why does this happen?

3 vues (au cours des 30 derniers jours)
function NextButtonPushed(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
RightAscensionDate; % this is a function I need to run.
run('ApogeePerigeeApp.mlapp');
end
end

Réponse acceptée

Rik
Rik le 29 Nov 2018
The use of globals makes this an impossible task to debug. How are you making sure they are non-empty scalar values? If they aren't, the logical comparisons will yield either an empty logical array (not checked if that's true), or they will return a logical array, on which you can't use the short circuit operands.
The source of your problem is probably there.
  4 commentaires
Riccardo Basile
Riccardo Basile le 1 Déc 2018
After some debugging I found out that those variables were always empty for some reason... I had to define those variables as properties of the app instead of using globals. And yes, apparently data is not always in the expected form! Also it looks like globals are a bad idea more often than not... Thank you for your help!
Rik
Rik le 1 Déc 2018
You're very welcome, glad to be of help.
And yes, globals can be very tricky to use and almost always be avoided.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer 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