how to make an array with only single numbers from 1 till n

31 次查看(过去 30 天)
hey,
i was wondering how i can make a single array (a) from 1 till n where are only single numbers in it. so if you have an array with 19 numbers it should look like a= [1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 ] i hope someone can help me out.

采纳的回答

Massimo Zanetti
Massimo Zanetti 2016-10-8
编辑:Massimo Zanetti 2016-10-8
Here it is
m=1:14
s=regexprep(num2str(m),' ','')-48

更多回答(2 个)

KSSV
KSSV 2016-10-8
a1=1:9;
a2=ones(1,20);
a2(2:2:end)=0:9;
a = [a1 a2]
I tried without matlab here. Play around if result is not as expected.

Guillaume
Guillaume 2016-10-8
Another option, possibly faster:
n = 19;
sprintf('%d', 1:n) - '0'

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by