surf won't display zeros in the last row?

1 次查看(过去 30 天)
I wanted to visualize binary vectors (of length 15) in black and white, so I wrote the following code to utilize surf:
vector = ones(1,15);
black = [1,5,14,15];
vector(black) = zeros(1,length(black));
fig_handle = figure;
surf([vector; vector]')
axis([1,2,1,16])
set(gca,'XTick',[])
set(gca,'XTickLabel',[])
set(gca,'YTick',[2,4,6,8,10,12,14])
set(gca,'YTickLabel',{'2','4','6','8','10','12','14'})
caxis([0 1])
colormap gray
view(0,270)
It works exactly as I want as long as "black" doesn't contain 15. When it does, no matter what I try, the fifteenth entry in the image remains white.
Suggestions? Thanks.

采纳的回答

Chad Gilbert
Chad Gilbert 2013-7-18
The surf command is plotting from 1 to 15. If you want to show the width of the 15th block, you'll need to supply data up to 16. Changing your surf line to:
surf([1 2],1:16,[[vector; vector]'; [0 0]])
made your plot work for me. Also, if you want to create a 2D plot, as you are here, you can use pcolor instead of surf.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Orange 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by