How can I make my function or variable defined if it is undefined?

1 vue (au cours des 30 derniers jours)
Zachary
Zachary le 7 Mar 2013
Trying to run a code but it keeps giving me the error that 'cr' is undefined. I don't know why.
R=input('Enter the R value for the RGB color model:');
G=input('Enter the G value for the RGB color model:');
B=input('Enter the B value for the RGB color model:');
if(0>R||R>255)
disp('Invalid RGB value.')
return;
elseif(0>G||G>255)
disp('Invalid RGB value.')
return;
elseif(0>B||B>255)
disp('Invalid RGB value.')
return;
elseif(R==G==B)
cr='Gray';
elseif(R>=G>=B)
cr='Red-Yellow';
elseif(G>R>=B)
cr='Yellow-Green';
elseif(G>=B>R)
cr='Green-Cyan';
elseif(B>G>R)
cr='Cyan-Blue';
elseif(B>R>=G)
cr='Blue-Magenta';
elseif(R>=B>G)
cr='Magenta-Red';
else
disp('Error.')
end
fprintf('%s',cr)

Réponse acceptée

Matt J
Matt J le 7 Mar 2013
This
G>=B>R
should really be
G>=B && B>R
The same with the rest of your triple logical expressions.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots 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!

Translated by