This is very easy thing
Easy problem! Great!
Great beginner problem!
the solution is well used by day to day users in matlab
It is so easy.Don't you think?
what is difference between 123456 and 1 2 3 4 5 6 vectors?
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.
Great idea to learn colon notation! Thanks!
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?
i need more points
link is very helpful
it's magic ^_^
Well crafted problem!
you are sooo right
Easy way to learn concatenation :)
linspace gives you a smaller size :)
is it ok
wow very fun!
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.
This user (mohamed elbesealy) appears to have gamed the system, with fraudulent "likes" of this unremarkable solution submitted by 'sock-puppet' accounts. —DIV
This user (ALBERT ALEXANDER STONIER) appears to have gamed the system, with fraudulent "likes" of this unremarkable solution submitted by 'sock-puppet' accounts. —DIV
i really don't get why it is wrong lol
try again you are so best
This really saves time!
what about x = 1:10;
im also wondering why ' x=1:10' doesn't work
try it without using ' ' (x = 1:10;)
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.
remove the square brackets,size will reduce even more
why isnt the  notation required for the solving of the puzzle?
how do you improve on this solution?
Shorter than mine.
ermmm why not? It works when I type it in...
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.
x=1:10 do the same.
I do not deem that these problems can enhance one's performance.....
This question could have been a bit more challenging.
why is this incorrect?
You need to insert "function x=oneToTen" as the first line of your function.
give a value of y simple calling the function oneToTen. it will definitely work
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
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).
If I were to type this in to MATLAB right now, it absolutely would create the desired vector. I don't think I understand Cody.
Cody requires you to define a function, so you have to precede this statement by an appropriate function statement.
please unlock the solution
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!
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.
Cannot be reproduced, creates an error in execution in R2016a.
Back to basics 7 - Equal NaNs
Given a matrix, swap the 2nd & 3rd columns
Sum of odd numbers in a matrix
Produce a sine wave
Return the 3n+1 sequence for n
Find common elements in matrix rows
Find the sum of all the numbers of the input vector
Find the two most distant points
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office