MATLAB Function to Identify Consecutive Repeating Numbers, Exercises of Signals and Systems Theory

The matlab code for a function named 'dsc' that identifies and returns consecutive repeating numbers in a given input vector. The function uses a for loop and conditional statements to compare each element in the vector with the previous one, and if they are the same, the loop continues to search for the next repeating number. The function returns an output vector 'b' containing the consecutive repeating numbers.

Typology: Exercises

2011/2012

Uploaded on 07/14/2012

kapor
kapor 🇮🇳

4

(1)

37 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
a=[1 2 2 2 3 1] %input
dsc (a) % calling function
function z=dsc(a) %function definition
c=2;
b(1)=a(1);
for(x=2:1:length(a))
if (a(x)==a(x-1))
x=x+1;
else
b(c)=a(x);
x=x;
c=c+1;
end
end
b %output
docsity.com

Partial preview of the text

Download MATLAB Function to Identify Consecutive Repeating Numbers and more Exercises Signals and Systems Theory in PDF only on Docsity!

a=[1 2 2 2 3 1] %input dsc (a) % calling function function z=dsc(a) %function definition c=2; b(1)=a(1); for(x=2:1:length(a)) if (a(x)==a(x-1)) x=x+1; else b(c)=a(x); x=x; c=c+1; end end b %output

docsity.com