MATLAB: How to make the function or variable defined if it is undefined

undefined functionundefined variable

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)

Best Answer

This
G>=B>R
should really be
G>=B && B>R
The same with the rest of your triple logical expressions.
Related Question