How to use boxes to plot a freqency band?

2 Ansichten (letzte 30 Tage)
Travis
Travis am 30 Aug. 2011
I'd like to create a plot that looks similar to this:
Row1:| [_____] [_______] [_] [___] [___________]
Row2:| [________] [_] [______] [_________]
|____________________________________________________
Frequency
The idea is that Row1 and Row2 contain frequency spans that I would like to identify with boxes.
I can't seem to make the horizontal bar graph do something like this.
Any help is greatly apprecited. Thanks all!

Antworten (2)

Rick Rosson
Rick Rosson am 30 Aug. 2011
You may want to consider using patch objects. For more information:
>> doc patch
HTH.
Rick

Oleg Komarov
Oleg Komarov am 31 Aug. 2011
% I suppose you have the starting and ending point of each block. % You have to ensure that they are monotonically increasing across rows and the number of columns is even.
sten = [1 3 7 14 16 17;
2 4 8 9 11 19];
% Create X coordinates for the boxes
clear X
szSt = size(sten);
df = diff(sten,[],2);
X(:,1:2:szSt(2)*2) = [sten(:,1) df];
X = [cumsum(X,2) sten(:,end)];
% Create the Y coordinates for the boxes
Y = repmat(bsxfun(@minus,[2.5; 1.5; 1.5; 2.5],0:szSt(1)-1), szSt(2)/2,1);
% Reshape
X = reshape(X.',4,[]);
Y = reshape(Y,4,[]);
% Figure and axes
figure('units','pix','pos',[300 200 640 140])
axes('units','pix','pos',[20 20 600 100],'Xlim',[0 max(sten(:))+1],...
'Ylim',[0 szSt(1)+.5],'Ytick',1:szSt(1),'YtickL',szSt(1):-1:1)
patch(X,Y,ones(size(X)))

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by