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

2 views (last 30 days)
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)

Accepted Answer

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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!