how create cell 1:10 vertical

4 views (last 30 days)
aldo on 12 Nov 2023
Edited: John D'Errico on 12 Nov 2023
c={(1:10)'}
c = 1×1 cell array
{10×1 double}
%but is not correct..i want to creare 1x10cell

Dyuman Joshi on 12 Nov 2023
c = (1:10).';
c = num2cell(c)
c = 10×1 cell array
{[ 1]} {[ 2]} {[ 3]} {[ 4]} {[ 5]} {[ 6]} {[ 7]} {[ 8]} {[ 9]} {[10]}
3 CommentsShow 1 older commentHide 1 older comment
Dyuman Joshi on 12 Nov 2023
c = (1:10)
c = 1×10
1 2 3 4 5 6 7 8 9 10
For real numbers, ctranspose, ' is equal to transpose, .'
c.'
ans = 10×1
1 2 3 4 5 6 7 8 9 10
c'
ans = 10×1
1 2 3 4 5 6 7 8 9 10
aldo on 12 Nov 2023
okkk

John D'Errico on 12 Nov 2023
Edited: John D'Errico on 12 Nov 2023
There are always many ways to solve a problem. An easy way to create the cell array directly is to do this:
C1 = {1;2;3;4;5;6;7;8;9;10}
C1 = 10×1 cell array
{[ 1]} {[ 2]} {[ 3]} {[ 4]} {[ 5]} {[ 6]} {[ 7]} {[ 8]} {[ 9]} {[10]}
And, yes, that works nicely for a small array, but for a larger one you will want to use another tool. num2cell is a good choice, as suggested already. mat2cell will also work, but not quite as nicely.