Problem 2. Make the vector [1 2 3 4 5 6 7 8 9 10]
In MATLAB, you create a vector by enclosing the elements in square brackets like so:
x = [1 2 3 4]
Commas are optional, so you can also type
x = [1, 2, 3, 4]
Create the vector
x = [1 2 3 4 5 6 7 8 9 10]
There's a faster way to do it using MATLAB's colon notation.
Solution Stats
Problem Comments
-
44 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
outrageously difficult
This was a cool one
ชิลๆๆ
this was a very cool problem
very simple
I really liked this problem. Short and simple.
Solution Comments
Show commentsProblem Recent Solvers49333
Suggested Problems
-
Get the length of a given vector
10951 Solvers
-
618 Solvers
-
Reverse the elements of an array
1023 Solvers
-
13771 Solvers
-
Find out sum and carry of Binary adder
1486 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!