Plotting a piecewise constant waveform with 1000 data points

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
Ugongorr
Messages
1
Reaction score
0
My mat lab skills are pretty low, basically i want to know how to make a waveform using 1000 points of data.

if the data is for example

y = 1 for 0<n<0.1
y = 2 for 0.1<n<0.5
y = -5 for 0.5 < n < 1

so how could i plot this waveform using 1000 points of data

cheers
 
Physics news on Phys.org
Try this and see what happens

y = zeros(1000);
for i=1:100
y(i) = 1;
end;
for i=101:500
y(i) = 2;
end;
for i=501:1000
y(i) = -5;
end;
plot(y)