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));
|
657 Solvers
6360 Solvers
MATCH THE STRINGS (2 CHAR) very easy
250 Solvers
347 Solvers
364 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!