It works, but it's ugly :-)
Nice! :)
Never realized that MATLAB sees a defined assignment (y = 2*x) different than no assignment (2*x => assignment to ans).
If anything, I would have guessed the second would be (slightly) more effort.
does this variable "ans" overrides MATLAB's default "ans"?
ok, i got there in the end. but it defeats the rules - there is no "y" variable when you change the template to ans = times2(x)...
how do you know what the rules are?!?
comment section gives a great info
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
assert(isequal(times2(1),2));
|
2 | Pass |
%%
assert(isequal(times2(11),22));
|
3 | Pass |
%%
assert(isequal(times2(-3),-6));
|
4 | Pass |
%%
assert(isequal(times2(29),58));
|
707 Solvers
501 Solvers
Convert a vector into a number
503 Solvers
Finding perimeter of a rectangle
278 Solvers
2028 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!