Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Matlab Function Problem

Status
Not open for further replies.

newatmatlab

New Member
HI! I've been assigned a problem in which I must "write a function with header [boundedB] = myBoundingArray(B, top, bottom) where boundedB is equal
to the array B wherever bottom < B < top, boundedB is equal to bottom wherever B < bottom, and boundedB is equal to top wherever B > top. You may assume that B is a one dimensional double array and that top and bottom are 1x1 doubles."

Test Cases:
>> B= myBoundingArray(-5:5, 3, -3)
B =
-3 -3 -3 -2 -1 0 1 2 3 3 3

I have written the code:

indices=find(bottom<A & A<top);
boundedA=A;
%boundedA(indices(bottom<A & A<top));


%boundedA=bottom wherever A<bottom
indices=find(A<bottom);
boundedA=bottom;
boundedA(indices(A<bottom));


%boundedA=top wherever A>top
indices=find(A>top);
boundedA=top;
boundedA(indices(A>top));

Which my TA says is super close, but I am making a mistake on the last "boundedA(indices(...))" lines. I was wondering if anyone had any advice or pointers?

Thank so much in advance!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top