1, 4, 7, 2, 5, 8, 3, 6, 9 serie

36 次查看(过去 30 天)
Octavio
Octavio 2013-6-21
Hi, at some point in my MATLAB code I need to generate the following serie of numbers 1,4,7, 2, 5, 8, 3, 6, 9 I can't find the way to please can you help me ?
Thank you !

采纳的回答

Tom
Tom 2013-6-21
a = reshape(1:9,3,3)';
a = a(:)'

更多回答(1 个)

John D'Errico
John D'Errico 2022-9-15
编辑:John D'Errico 2022-9-15
Yes, @Tom has given a great answer. The way I would solve it on any normal day. But, just perhaps, is there another way? There always is...
ind = 0:8;
1 + 3*mod(ind,3) + floor(ind/3)
ans = 1×9
1 4 7 2 5 8 3 6 9
Look carefully at how it works. Take apart each piece.

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by