Azzera filtri
Azzera filtri

surf won't display zeros in the last row?

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Chad Gilbert
Chad Gilbert il 18 Lug 2013
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.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by