Cannot plot a point in the color black
이전 댓글 표시
Hi,
I am using a for loop to store 1x3 vectors, each in a cell of a cell array. Each vector defines a color which is used to plot a datapoint. I am using that for loop because I need to plot different points in different colors, depending on the value of the data. I have no difficulty plotting points in non-black colors (ex: [1 0 0] for red), but when my cell array entry is supposed to be [ 0 0 0], it becomes [ ] . This causes an error when I try to plot the datapoint corresponding to that vector:
plot(x(i),datapt(i),'Color',colorcellarray{i})
Error using plot
Color value must be a 3 element vector
The same error occurs when I try to use 'k' in that cell array entry.
Does anyone have any ideas how to work around this problem? Thank you!
답변 (1개)
Star Strider
2020년 10월 3일
One line of code does not tell everything about what you are doing. I have no problem plotting in any of these colours.
Try this:
x = 0:9;
datapt = randn(size(x));
colorcellarray = {'k','c','m','y','k','r','g','b',[0.8 0.5 0.2],[0.1 0.35 0.65]};
figure
hold on
for i = 1:numel(x)
plot(x(i),datapt(i),'p','Color',colorcellarray{i},'MarkerSize',10,'MarkerFaceColor',colorcellarray{i})
end
hold off
grid
.
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!