Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top