Creating a row by 1 matrix

1 view (last 30 days)
Nik
Nik on 30 Nov 2014
Answered: the cyclist on 30 Nov 2014
Hi, I'm still a beginner in MATLAB. I wanna create a matrix with row by 1 . Row is a variable. Let say row = 4 then I want MATLAB to display it like below
1
2
3
4
how can i write the code to automatically generate it with increment by 1?

Accepted Answer

the cyclist
the cyclist on 30 Nov 2014
One of many way to do this:
variable = (1:row)'
  2 Comments
Nik
Nik on 30 Nov 2014
Tq sir, really appreciate it.If possible can you show me some of the alternative way of doing it?
the cyclist
the cyclist on 30 Nov 2014
I'll add a few more as other answers. Most would be rather obscure or silly to actually use for this purpose, but you can see some interesting functions.

Sign in to comment.

More Answers (3)

the cyclist
the cyclist on 30 Nov 2014
variable = triu(1:row)'

the cyclist
the cyclist on 30 Nov 2014
variable = diag(diag(1:row))

the cyclist
the cyclist on 30 Nov 2014
variable = linspace(1,row,row)'

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!