y = sum(x=='1');
Well, well! Here he/she is as well, great job continuing your copy and paste of the cheap and meaningless trick you prick!
In case you didn't know how to do it and wanted to know how -which somehow I doubt it for some reason!, but anyhow, here is one of MANY ways to do it:
function x=one(x),x=count(x,'1');end
y = length(find(x=='1'));
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
x = '0000';
y_correct = 0;
assert(isequal(one(x),y_correct));
[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.]
[> In unix (line 32)
In one (line 2)
In ScoringEngineTestPoint1 (line 3)
In solutionTest (line 3)]
|
2 | Pass |
x = '111';
y_correct = 3;
assert(isequal(one(x),y_correct));
[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.]
[> In unix (line 32)
In one (line 2)
In ScoringEngineTestPoint2 (line 3)
In solutionTest (line 5)]
|
3 | Pass |
x = '1100101';
y_correct = 4;
assert(isequal(one(x),y_correct));
[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.]
[> In unix (line 32)
In one (line 2)
In ScoringEngineTestPoint3 (line 3)
In solutionTest (line 7)]
|
267 Solvers
349 Solvers
Find the dimensions of a matrix
372 Solvers
307 Solvers
Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock.
761 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!