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

조회 수: 1 (최근 30일)
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)

채택된 답변

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by