From: ImageAnalyst on
Dave Smith:
This is very easy. Just use the line command. You give it the x1,y1
and the x2,y2 (end points of the line) and it does it. You just need
to figure out what they are (and it sounds like you already know that,
you just need to know how to plot it.)

Like this

X=rand(1,20);
plot(X);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
hold on;
line([2 7], [0.5 0.5], 'LineWidth', 3, 'Color', [0 .4 0]);
line([7 7], [0.5 0.3], 'LineWidth', 3, 'Color', [.8 0 0.1]);
line([7 17], [0.3 0.3], 'LineWidth', 3, 'Color', [0 .4 0]);
From: Dave Smith on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <bc83d7f7-f279-4c88-bb19-fc8b9edf11b6(a)g7g2000yqe.googlegroups.com>...
> Dave Smith:
> This is very easy. Just use the line command. You give it the x1,y1
> and the x2,y2 (end points of the line) and it does it. You just need
> to figure out what they are (and it sounds like you already know that,
> you just need to know how to plot it.)
>
> Like this
>
> X=rand(1,20);
> plot(X);
> set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
> hold on;
> line([2 7], [0.5 0.5], 'LineWidth', 3, 'Color', [0 .4 0]);
> line([7 7], [0.5 0.3], 'LineWidth', 3, 'Color', [.8 0 0.1]);
> line([7 17], [0.3 0.3], 'LineWidth', 3, 'Color', [0 .4 0]);

I don't really understand this. Look like you're just drawing line on top on the plot where as I'm trying to draw digital signal with 0 and 1 from any binary input. Could it be I don't know how to apply this to my problem.
From: ImageAnalyst on
Well I showed you how to draw a line because you said "How do I make
the plot graph draw a line..." and then you gave a series of line
segments. If you want to do it all in one shot with the plot command,
then you're going to have to double up on some x values - insert an
coordinate at the same x value but a different y value. Plot can plot
a polyline but you have to give it all the coordinates (vertices) of
the polyline you want to plot.
From: dpb on
Dave Smith wrote:
> dpb <none(a)non.net> wrote in message
> <hn0uph$jl1$1(a)news.eternal-september.org>...
>> Dave Smith wrote:
>> > dpb <none(a)non.net> wrote in message >
>> <hn0k4h$9c1$1(a)news.eternal-september.org>...
>> ...
>>
>> > Thank you. This is very close to what i wanted but can you explain
>> what > is rand(size(x)) do?
>> Just generated a set of random numbers to start w/ of the same size as
>> x...
>>
>> ...
>>
>> > a horizontal line and a vertical line going down from 2 and then
>> another > horizontal line from 2-3. I hope you understand what I'm
>> trying to said.
>>
>> Yeah, you'll have to duplicate the x-coordinates at the break points
>> which the above doesn't do (didn't think thru the issue thoroughly
>> enuf before, sorry).
>>
>> The fundamental idea is the same, just that you'll have to have the x
>> and y vectors contain the entries for both the (replicating) abcissa
>> and ordinates to draw a true square wave. What I showed would be a
>> triangle, indeed.
>>
>> Of course, a true square wave is an idealization anyway, no matter how
>> good the rise/fall time of a wave generator... :)
>>
>> If you perchance have the Signal Processing toolbox, it has a square()
>> function but it is "realizable" in the above sense as it doesn't
>> generate values at duplicated time points, either.
>>
>> --
>
> duplicate x-coordinates? can you help me out, I been struggling with
> this all day, so frustrating

Well, you have to decide the on/off positions but you need something like

x = [ 0 1 2 2 3 4 5 5 6 7 8 8 9 10 ];
y = [ -1 -1 -1 1 1 1 1 -1 -1 -1 -1 1 1 1 ];
plot(x,y)
axis([0 10 -2 2]) % fix y-axis so can see clearly now...

The trick is to determine programmatically what are the breakpoints
where you need the duplicated x values to create the vertical
transition. (Assuming that is what you really want irrespective of the
realizability issues raised earlier)

--
From: Walter Roberson on
Dave Smith wrote:
> How do I draw a digital signal on the plot graph? let says I have 10
> points incrementing by 1. How do I make the plot graph draw a line from
> x-axis = 0-1, 1-2, 2-3, 3-4, 4-5, 5-6, 7-8, 8-9, 9-10, etc. The line can
> be at y-axis = 1, 0, or -1 depend on what I want at those points? Lines
> also have to be connected as well so it's like a digital signal. I'm
> looking for a for loop that can do this or something better.

Presuming that you want the signal to start at 0 and to return to 0, then:

newx = reshape(repmat(1:length(y)+1,2,1),1,[]);
newy = [0 reshape(repmat(y(:),1,2).',1,[]) 0];