index out of bounds
조회 수: 1 (최근 30일)
이전 댓글 표시
hi guys, new to matlab and came across a simple problem that takes me forever to get over. please help.
if rgb(1)==1
if rgb(2)==1
if rgb(3)==1
color='white';
else
color='yellow';
end
else
if rgb(3)==1
color='magenta';
else
color='red';
end
end
else
if rgb(1)==1
if rgb(3)==1
color='cyan';
else
color='green';
end
else
if rgb(3)==1
color='blue';
else
color='invalid input';
end
end
end
so its pretty much just mix three primary colors as input and output the mixed color.. i have a hard time going through this and i don't know where i did wrong.. thanks for answering. oh and here's the error:
Attempted to access rgb(3); index out of bounds because numel(rgb)=1.
Error in rgb_color (line 26) if rgb(3)==1
댓글 수: 0
채택된 답변
Ilham Hardy
2015년 10월 30일
편집: Ilham Hardy
2015년 10월 30일
What is your rgb value?
The error message is very clear. it stated that you tried to access the third index of rgb, whilst rgb only contains one value ( numel(rgb)=1).
댓글 수: 5
Walter Roberson
2015년 10월 30일
How are you invoking your code? I can see your file is named rgb_color.m but how are you starting it running?
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!