used y=y+str2double(x(i)) instead of y=y+str2double(x(i)) and it worked just fine
function y = one(x)
y1=[];
for a=x(1:end)
y1 = [y1,str2num(a)];
end
y=sum(y1);
end
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
x = '0000';
y_correct = 0;
assert(isequal(one(x),y_correct));
|
2 | Pass |
x = '111';
y_correct = 3;
assert(isequal(one(x),y_correct));
|
3 | Pass |
x = '1100101';
y_correct = 4;
assert(isequal(one(x),y_correct));
|
875 Solvers
Back to basics 23 - Triangular matrix
634 Solvers
Switch matrix to a column vector
260 Solvers
992 Solvers
556 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!