Sunday, September 20, 2009

Get desired elements from the given array in Matlab

A very simple function to collect the items from the array which meets the required condition




clear all
A=[1,2,3,4,5,6,7,8,9,10];
B=zeros(1,length(A));
k=1;
diff = A(1);
B(1) = diff;
for i=2:length(A)
diff=diff+3;
    B(i) = diff;

end
B = B(B<=max(A))

No comments: