Problem 2. Make the vector [1 2 3 4 5 6 7 8 9 10]
Solution Stats
Problem Comments
-
38 Comments
Nice problem
nice
This is very easy thing
Great!
nice
Easy problem! Great!
Love it!
nice
Very interesting!
Great beginner problem!
nice
nice
nice
nice
nicer
nice
great
good start
very good
the solution is well used by day to day users in matlab
a=1:10
It is so easy.Don't you think?
what is difference between 123456 and 1 2 3 4 5 6 vectors?
good
Yeah, I personally like the colon operator for creating vectors!
@Muhammad Tanveer: if you take 123456 (without commas, semicolons or spaces), it is one (huge) number.
You can create a vector both by enclosing the elements in square brackets like v=[1 2 3 4 5] or using commas, like v=[1,2,3,4,5]. They mean the very same: a vector (matrix) of 1 row and 5 columns. It is up to you.
If you used a semicolon (;), then v=[1;2;3;4;5] means something else: a vector of 5 rows and one single column.
awesome!
Great idea to learn colon notation! Thanks!
cool
Why did I copy the code to the matlab editor and run it but the command line window says I didn't define a function or variable?
Easy ;)
good
easy stuff
i need more points
link is very helpful
good problem
Good practice.
good problem
Solution Comments
-
1 Comment
use colon notation
-
2 Comments
Nice
good
-
1 Comment
good problem
-
2 Comments
good problem.
GOOD
-
1 Comment
it's magic ^_^
-
1 Comment
easy
-
1 Comment
Well crafted problem!
-
1 Comment
super
-
1 Comment
great problem
-
1 Comment
you are sooo right
-
1 Comment
Easy way to learn concatenation :)
-
1 Comment
easy
-
1 Comment
very easy
-
1 Comment
How come?
-
1 Comment
linspace gives you a smaller size :)
-
1 Comment
is it ok
-
1 Comment
Great problem
-
2 Comments
wow very fun!
[1:1:10]
-
1 Comment
why not
-
2 Comments
Nice. What is the difference between this vector and x = linspace(1,10,10)?
Hello Matthew Jones,
Linspace is similar to the colon operator ":", but gives direct control over the number of points.
In x = linspace(1,10,10) you directly enter the number of points and the function generates equally spaced vector but when you use ":" operator, you need to mention step size.
-
1 Comment
.
-
1 Comment
good job
-
1 Comment
This user (mohamed elbesealy) appears to have gamed the system, with fraudulent "likes" of this unremarkable solution submitted by 'sock-puppet' accounts. —DIV
-
1 Comment
This user (ALBERT ALEXANDER STONIER) appears to have gamed the system, with fraudulent "likes" of this unremarkable solution submitted by 'sock-puppet' accounts. —DIV
-
2 Comments
i really don't get why it is wrong lol
try again you are so best
-
1 Comment
This really saves time!
-
4 Comments
what about x = 1:10;
im also wondering why ' x=1:10' doesn't work
no,it works
try it without using ' ' (x = 1:10;)
Nice!
-
2 Comments
I have tried multiple things that would create that vector, and it won't accept my answer. I am not sure what this question wants from me I guess.
The output of your function is x, not x_correct, so remove "_correct" and it should work.
-
1 Comment
remove the square brackets,size will reduce even more
-
1 Comment
why isnt the [] notation required for the solving of the puzzle?
-
1 Comment
how do you improve on this solution?
-
1 Comment
Shorter than mine.
-
1 Comment
ermmm why not? It works when I type it in...
-
3 Comments
Please help!!!!not sure where i went wrong
You just need to type x=[1,2,3,4...10] or x=1:10
Just edit that line in the code. Not the whole thing
You should name the function exatly 'oneToTen',and apparently,your x is from 1 to 9,not 1 to 10.
-
1 Comment
x=1:10 do the same.
-
1 Comment
I do not deem that these problems can enhance one's performance.....
-
1 Comment
This question could have been a bit more challenging.
-
2 Comments
why is this incorrect?
You need to insert "function x=oneToTen" as the first line of your function.
-
1 Comment
give a value of y simple calling the function oneToTen. it will definitely work
-
1 Comment
I do not understand the point of Cody... I cannot use "eval 1:10;" but I can use "str2num 1:10;" which is overhead + eval 1:10... Please make Cody evaluate the functions used in submitted code
-
2 Comments
what's the "str2num" mean?
str2num means "convert string to number"; even more cryptic is the fact that "str2num 1:10" is equivalent to "str2num('1:10')" (Matlab allows you to omit the single quotes and parentheses when using functions that take character strings as arguments).
-
2 Comments
-
1 Comment
please unlock the solution
-
5 Comments
I’ve found that the huge strength of MATLAB is that it frees me to rapidly prototype numerical math problems – before I design a targeted solution. Such esoteric efficiencies as above are very clever and much credit goes to the person who presented it, however, this distracts rather than adds significant value to my use of MATLAB. Depending on the target machine (Desktop workstation or embedded device) I will ultimately use C/C++, assembly and VHDL to implement my process efficient code – never an interpreted language.
This is an update since I had one person ask about my post...
I believe that speed is only one metric of performance, another is memory utilization. The key in this problem is the “type” of the variable stored internally. By using ans=1:10; the variable ans is (I believe) of the type double precision floating point (8 Bytes for each number). On the other hand by using str2num, a cast to an array of Characters (1 Byte each) is used to tightly store the tiny integer range of numbers needed. Thus the memory required to store ans is 8 times less.
SO, I’m not sure how they actually score (or weight) the importance between memory efficiency and execution time (and across multiple platforms and OS’s) since in your case you claim a faster execution time without the casting. This would need to be asked to a Mathworks person with specific insight to their code – sorry.
And back to my soapbox point… I’m using a machine that has 12 GB of RAM, so the difference between using 10 bytes or 80 bytes is not important to me.
HOWEVER, understanding this issue IS important so my hat is off to the Cody folks for the great (and fun) challenge!
Hope that helps!
john
The metric used to evaluate the performance of a solution is http://www.mathworks.com/matlabcentral/fileexchange/34754-calculate-size
As you can see if you inspect the code, it has nothing to do with speed or memory. That is why I proposed this solution, in order to show that you can become the leader with a code that is not efficient at all, either in execution speed or in memory use. Although I think the idea of Cody is great and challenging I believe that the metric that is used nowadays should be rethought.
interesting
Cannot be reproduced, creates an error in execution in R2016a.
-
1 Comment
cumsum(ones(1,10))
Problem Recent Solvers43954
Suggested Problems
-
Find the peak 3n+1 sequence value
1815 Solvers
-
Renaming a field in a structure array
1193 Solvers
-
4407 Solvers
-
Flip the vector from right to left
6561 Solvers
-
697 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!