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