How to code to get this output

8 次查看(过去 30 天)
Muhamad Bunaiya
Muhamad Bunaiya 2018-4-5
评论: Greg 2018-4-5
xt=[1 2 3 4 5 6 7 8 9 10 11]
for m=1:25
Output supposely
xt1 = [1 2 3 4 5 6 7 8 9 10 11]
xt2 =[1 2 3 4 5 6 7 8 9 10 11]
.
.
.
.
.
.
.
xt25 =[1 2 3 4 5 6 7 8 9 10 11]
What should i do to get this output
  1 个评论
Greg
Greg 2018-4-5
编辑:Greg 2018-4-5
You should read any of the umpteen million discussions of why this (dynamically generating variable names) is a bad idea. There is no reason not to use the following with proper indexing:
xt = repmat(1:11,25,1);

请先登录,再进行评论。

回答(1 个)

Birdman
Birdman 2018-4-5
Do not dynamically create variables. It is not recommended. Instead, use a multidimensional array:
for m=1:25
xt(:,:,m)=1:11;
end
  1 个评论
Greg
Greg 2018-4-5
Why the loop, and why the third dimension?
xt = repmat(1:11,25,1);
Or
xt = repmat(1:11,1,1,25); % If you really want the third dimension

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by