Collect for loop output into one variable

1 回表示 (過去 30 日間)
Craig
Craig 2013 年 3 月 8 日
Very basic problem problem, is there a quicker, neater way of doing the below:
m=13:21
for o=0:61;
p=m+(11*o);
eval(sprintf('p%d=p',o));
end
n=[p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10... p61]
Want to produce a variable 'n' consisting of values 13-21, 24-32, etc til 684-692. (So 9 numbers, miss 2, next 9 numbers..). Output needs to be as one row so 'n' can be used for another for loop.
Aware this will be ridiculously simple but new to matlab.
Thanks

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 8 日
編集済み: Azzi Abdelmalek 2013 年 3 月 8 日
m=13:21
for o=0:61;
b(o+1,:)=m+(11*o)
end
b=b',
out=b(:)'
%or
m=13:21
b=[];
for o=0:61;
b=[b m+(11*o)]
end
%or
m=13:21
out=cell2mat(arrayfun(@(x) m+11*x,0:61,'un',0))
  1 件のコメント
Craig
Craig 2013 年 3 月 8 日
Thank you for your help Azzi

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by