Can someone check this code?
function y = one(x)
split1= num2cell(x)
sum=0;
for i=1:length(split1)
if split1(i)=='1'
sum=sum+1
else
sum=0
i=i+1
y = sum;
end
Test | Status | Code Input and Output |
---|---|---|
1 | Fail |
x = '0000';
y_correct = 0;
assert(isequal(one(x),y_correct));
split1 =
1×4 cell array
{'0'} {'0'} {'0'} {'0'}
|
2 | Fail |
x = '111';
y_correct = 3;
assert(isequal(one(x),y_correct));
split1 =
1×3 cell array
{'1'} {'1'} {'1'}
|
3 | Fail |
x = '1100101';
y_correct = 4;
assert(isequal(one(x),y_correct));
split1 =
1×7 cell array
{'1'} {'1'} {'0'} {'0'} {'1'} {'0'} {'1'}
|
middleAsColumn: Return all but first and last element as a column vector
387 Solvers
359 Solvers
664 Solvers
326 Solvers
String Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values
358 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!