[SOLVED] Creating A Step Array in Matlab

Status
Not open for further replies.

thaitam

Junior Member level 2
Joined
Nov 7, 2009
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,436
Hi

I have a set of discrete values say 10 however I wish to make this 100 values as the ten values all step to each other.

Using the stairs(x,y) command I can visualise however I need to expand the y values to 100 so that I can subtract the stair wave from a sine wave which has 100 elements.

Regards
thaitam
 

A simple Method

Code:
x1=[0 1 2 3 4 ];
>> x2=[x1,x1,x1,x1,x1];
>> y2=linspace(0,24,25);

stairs(y2,x2)


---------- Post added at 18:44 ---------- Previous post was at 18:40 ----------

 

Thanks!

I may not have been that clear basically I think I am wanting some form of zero order hold ie my original y array may be:

[0 1 2 3 4]

With an x array of

[0 1 2 3 4]

I however require this to become more elements such that for example 10 would result in a y array of
[0 0 1 1 2 2 3 3 4 4]

with an x array of
[0 0.5 1 1.5 2 2.5 3 3.5 4]

The example going from 5 to 10 is obviously an exagaration as the actual amount of points i require will be very large.

Thanks again!!
 

Yes it could be solved

and here is a function

Code:
%Blooz

function z=interpols(z,order) % Z is the original vector 
k=size(z,2);%k is the size of the vector 
temp=ones(1,k*order);% A temporary variable 
for i=1:k*order
   
    if (i==1)
        temp(i)=z(i);
    else 
    temp(i)=z(ceil(i/order));
    end 
  
end 
z=temp;%result stored in z 
end 
%End of the Function


result

Code:
>> z=[ 0 1 2 3 4];
>> interpols(z,2)

ans =

     0     0     1     1     2     2     3     3     4     4

>>
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…