How can I make my function or variable defined if it is undefined?
2 views (last 30 days)
Show older comments
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)
0 Comments
Accepted Answer
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.
0 Comments
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!