surf won't display zeros in the last row?

1 回表示 (過去 30 日間)
Erik
Erik 2013 年 7 月 18 日
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 Center および File ExchangeOrange についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by