MATLAB Comparing Array Elements With A Number Problem

Status
Not open for further replies.

LavezLas

Newbie level 5
Joined
Apr 4, 2013
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,337
Hi fellas,

I'm not familiar with MATLAB, and this year in our Introduction to DSP class, teacher gave us a homework but nearly none of us knows MATLAB much...

His question is;

Create an array with randomly-selected 1000 elements between -50 and 50. Compare
each element of the array such that;
If the element is greater than 30; change it as 30.
If the element is less than -30; change it as -30.
If the element is between -30 and 30; the element keeps its value.
Write the corresponding code for the question.
 

Hi guy,

no is hard make that.

You need make alone to learn, but I will help you.

create a script.

1 - Creat rand vector
r = randi(50,-50,1000); //see help to more informations
2 - flow control
Code:
for i=1:length(r)
 if r(i) > 30
 r(i) =30;
 else if r(i)<-30
 r(i) = -30;
... // u even finish
bye
 

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