function y = cleanUp(x)
x=[5 17 -20 99 3.4 2 8 -6]
for i=1:8
if (x(i)<0||x(i)>10)
y(i)=NaN;
else
y(i)=x(i);
end
end
Can anybody tell what is wrong with this code so that it is not clearing test 2.
Check this:Solution 181284.
x is input matrix which will vary rather being defined as in above program.
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
x = [ 5 17 -20 99 3.4 2 8 -6 ];
y_correct = [ 5 NaN NaN NaN 3.4 2 8 NaN ];
assert(isequalwithequalnans(cleanUp(x),y_correct))
x =
Columns 1 through 7
5.00 17.00 -20.00 99.00 3.40 2.00 8.00
Column 8
-6.00
|
2 | Fail |
%%
x = [ -2.80 -6.50 -12.60 4.00 2.20 0.20 -10.60 9.00];
y_correct = [ NaN NaN NaN 4.00 2.20 0.20 NaN 9.00]
assert(isequalwithequalnans(cleanUp(x),y_correct))
Error: Assertion failed.
|
We love vectorized solutions. Problem 1 : remove the row average.
546 Solvers
Find nearest prime number less than input number
268 Solvers
Find the index of the largest value in any vector X=[4,3,4,5,9,12,0,4.....5]
297 Solvers
Matlab Basics - y as a function of x
339 Solvers
1825 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!